Le 30/10/2026 à 13:56, Jerry DeLisle a écrit :
See attached patch. This is 1 of 2 to fix some loose ends in this effort.

Fairly self explanatory.

Regression tested on x86_64

OK for mainline?
This is mostly good; two cosmetic points below.


Regards,

Jerry


diff --git a/libgfortran/caf/shmem.c b/libgfortran/caf/shmem.c
index 964c7449e02..88b800e5247 100644
--- a/libgfortran/caf/shmem.c
+++ b/libgfortran/caf/shmem.c
@@ -266,7 +274,8 @@ _gfortran_caf_register (size_t size, caf_register_t type, 
caf_token_t *token,
   if (type != CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY)
     *token = malloc (sizeof (struct caf_shmem_token));
- size = alignto (size, sizeof (ptrdiff_t));
+  size = size > SIZE_MAX - sizeof (ptrdiff_t)
+        ? SIZE_MAX : alignto (size, sizeof (ptrdiff_t));
Can you put a comment somewhere telling that saturating to SIZE_MAX will end up being caught by the allocation code, resulting in a failed allocation? You mention it in the commit message, but it remains somehow implicit in the code itself.

   switch (type)
     {
     case CAF_REGTYPE_LOCK_STATIC:

@@ -309,7 +319,8 @@ _gfortran_caf_register (size_t size, caf_register_t type, 
caf_token_t *token,
allocator_lock (&local->ai.alloc);
        mem = alloc_get_memory_by_id_created (
-         &local->ai, size * local->total_num_images, next_memid, &created);
+         &local->ai, mul_size_sat (size, local->total_num_images), next_memid,
+         &created);
Please use a variable for the multiplication result, here...

        if (created)
          memset (mem, 0, size * local->total_num_images);
... and here, so that it remains apparent that we are clearing the same amount as allocated.

        allocator_unlock (&local->ai.alloc);

OK with these changes.

Reply via email to