diff options
author | Marc Poulhiès <poulhies@adacore.com> | 2022-06-30 09:50:02 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-07-12 12:24:15 +0000 |
commit | 6e3c2ee1d17a45eaf2095d4f64462da0993b881e (patch) | |
tree | dbad9d6c0a00c7f40aa0c98ce1993a0c4b7eba39 | |
parent | 33338e7289288404de79cb57dd1003a7552fb3d4 (diff) | |
download | gcc-6e3c2ee1d17a45eaf2095d4f64462da0993b881e.zip gcc-6e3c2ee1d17a45eaf2095d4f64462da0993b881e.tar.gz gcc-6e3c2ee1d17a45eaf2095d4f64462da0993b881e.tar.bz2 |
[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.
-rw-r--r-- | gcc/ada/libgnat/s-secsta.adb | 7 |
1 files changed, 6 insertions, 1 deletions
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; ---------------------- |