Skip to content

Commit f4ac440

Browse files
pmderodathainque
authored andcommitted
Files_Table.Expand_Line_Table: avoid big aggregate stack allocation
Change-Id: Id09c41ad21c093c26dbbc991e293aa14363baaff TN: QB14-023 (cherry picked from commit f2a1840)
1 parent 1be09f0 commit f4ac440

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tools/gnatcov/files_table.adb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,14 @@ package body Files_Table is
460460
return;
461461
end if;
462462

463-
New_Lines :=
464-
new Source_Line_Array'
465-
(FI.Lines.Last_Index + 1 .. Line =>
466-
(State => (others => No_Code), others => <>));
463+
-- Allocate the array first and then initialize it. Don't do it in one
464+
-- single statement as this would create a big aggregate on the stack,
465+
-- triggering a stack overflow when the number of line is too high.
466+
467+
New_Lines := new Source_Line_Array (FI.Lines.Last_Index + 1 .. Line);
468+
for Line of New_Lines.all loop
469+
Line := (State => (others => No_Code), others => <>);
470+
end loop;
467471

468472
Bump (Line_Table_Alloc);
469473
Bump (Line_Table_Alloc_Size, How_Many => New_Lines'Length);

0 commit comments

Comments
 (0)