public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1644] [Ada] Fix 0-sized secondary stack allocations
@ 2022-07-12 12:27 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-07-12 12:27 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6e3c2ee1d17a45eaf2095d4f64462da0993b881e

commit r13-1644-g6e3c2ee1d17a45eaf2095d4f64462da0993b881e
Author: Marc Poulhiès <poulhies@adacore.com>
Date:   Thu Jun 30 09:50:02 2022 +0200

    [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.

Diff:
---
 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 24b7601c4b5..359e9403339 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;
 
    ----------------------


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-12 12:27 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:27 [gcc r13-1644] [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).