[Bug libfortran/103634] Runtime crash with PACK on zero-sized arrays

anlauf at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Dec 9 18:27:57 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|fortran                     |libfortran
   Last reconfirmed|                            |2021-12-09
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from anlauf at gcc dot gnu.org ---
Untested fix:

diff --git a/libgfortran/intrinsics/pack_generic.c
b/libgfortran/intrinsics/pack_generic.c
index cad2fbbfbcd..f629e0e8469 100644
--- a/libgfortran/intrinsics/pack_generic.c
+++ b/libgfortran/intrinsics/pack_generic.c
@@ -126,6 +126,10 @@ pack_internal (gfc_array_char *ret, const gfc_array_char
*array,
   if (mstride[0] == 0)
     mstride[0] = mask_kind;

+  for (n = 0; n < dim; n++)
+    if (extent[n] == 0)
+      return;
+
   if (ret->base_addr == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or


More information about the Gcc-bugs mailing list