https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123832
Bug ID: 123832
Summary: Stack corruption when combining "&" and 'Image
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: liam at liampwll dot com
CC: dkm at gcc dot gnu.org
Target Milestone: ---
I'm not sure of the exact cause here, but the below trivial program seems to
cause some kind of stack corruption, specifically it overwrites an address
which ada.strings.text_buffers.unbounded.buffer_type.Finalize reads and causes
a segfault. I have also seen this silently corrupt data in a larger program.
This occurs on 16, 15.2, 14.3, 13.4, and 12.5.
pragma Ada_2022;
procedure Example is
type T is array (1 .. 13) of Integer;
function "&" (Left : T; Right : T) return T
is (others => 2);
-- Finalize will attempt to read at address 0xA when above is 2.
-- That changes to 0xB when above is 3.
function To_Virtual_String (Item : String) return T
is (others => 0);
procedure F (S : T) is null;
X : array (1 .. 1) of Integer := [others => 0];
begin
F ((others => 0) & To_Virtual_String (X'Image));
end Example;