Index: m4/reshape.m4
===================================================================
--- m4/reshape.m4	(Revision 175593)
+++ m4/reshape.m4	(Arbeitskopie)
@@ -101,6 +101,8 @@
 
   if (ret->data == NULL)
     {
+      index_type alloc_size;
+
       rs = 1;
       for (n = 0; n < rdim; n++)
 	{
@@ -111,7 +113,13 @@
 	  rs *= rex;
 	}
       ret->offset = 0;
-      ret->data = internal_malloc_size ( rs * sizeof ('rtype_name`));
+
+      if (unlikely (rs < 1))
+        alloc_size = 1;
+      else
+        alloc_size = rs * sizeof ('rtype_name`);
+
+      ret->data = internal_malloc_size (alloc_size);
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
 
Index: intrinsics/reshape_generic.c
===================================================================
--- intrinsics/reshape_generic.c	(Revision 175593)
+++ intrinsics/reshape_generic.c	(Arbeitskopie)
@@ -85,6 +85,8 @@
 
   if (ret->data == NULL)
     {
+      index_type alloc_size;
+
       rs = 1;
       for (n = 0; n < rdim; n++)
 	{
@@ -95,7 +97,14 @@
 	  rs *= rex;
 	}
       ret->offset = 0;
-      ret->data = internal_malloc_size ( rs * size );
+
+      if (unlikely (rs < 1))
+	alloc_size = 1;
+      else
+	alloc_size = rs * size;
+
+      ret->data = internal_malloc_size (alloc_size);
+
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
     }
 
