* [Ada] Fix 0-sized secondary stack allocations
@ 2022-07-12 12:25 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-07-12 12:25 UTC (permalink / raw)
To: gcc-patches; +Cc: Marc Poulhiès
[-- Attachment #1: Type: text/plain, Size: 286 bytes --]
The Has_Enough_Free_Memory was not correctly reporting a completely full
chunk in the case of a 0-sized allocation.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* libgnat/s-secsta.adb (Has_Enough_Free_Memory): Check for full
chunk before computing the available size.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 896 bytes --]
diff --git a/gcc/ada/libgnat/s-secsta.adb b/gcc/ada/libgnat/s-secsta.adb
--- a/gcc/ada/libgnat/s-secsta.adb
+++ b/gcc/ada/libgnat/s-secsta.adb
@@ -506,12 +506,17 @@ package body System.Secondary_Stack is
Mem_Size : Memory_Size) return Boolean
is
begin
+ -- First check if the chunk is full (Byte is > Memory'Last in that
+ -- case), then check there is enough free memory.
+
-- Byte - 1 denotes the last occupied byte. Subtracting that byte from
-- the memory capacity of the chunk yields the size of the free memory
-- within the chunk. The chunk can fit the request as long as the free
-- memory is as big as the request.
- return Chunk.Size - (Byte - 1) >= Mem_Size;
+ return Chunk.Memory'Last >= Byte
+ and then Chunk.Size - (Byte - 1) >= Mem_Size;
+
end Has_Enough_Free_Memory;
----------------------
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-12 12:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 12:25 [Ada] Fix 0-sized secondary stack allocations Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).