From 6e3c2ee1d17a45eaf2095d4f64462da0993b881e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc=20Poulhi=C3=A8s?= Date: Thu, 30 Jun 2022 09:50:02 +0200 Subject: [PATCH] [Ada] Fix 0-sized secondary stack allocations The Has_Enough_Free_Memory was not correctly reporting a completely full chunk in the case of a 0-sized allocation. gcc/ada/ * libgnat/s-secsta.adb (Has_Enough_Free_Memory): Check for full chunk before computing the available size. --- gcc/ada/libgnat/s-secsta.adb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/ada/libgnat/s-secsta.adb b/gcc/ada/libgnat/s-secsta.adb index 24b7601..359e940 100644 --- 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; ---------------------- -- 2.7.4