PR 78534, 83704 Handle large formatted I/O
[gcc.git] / libgfortran / runtime / in_pack_generic.c
index 34b55033caf62d47ba1b2ff8d855810f1ef1d163..dcc0db92ed3a9ec038988393cf006817cdab2881 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic helper function for repacking arrays.
-   Copyright (C) 2003-2013 Free Software Foundation, Inc.
+   Copyright (C) 2003-2018 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -24,8 +24,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
-#include <stdlib.h>
-#include <assert.h>
 #include <string.h>
 
 extern void *internal_pack (gfc_array_char *);
@@ -48,6 +46,9 @@ internal_pack (gfc_array_char * source)
   index_type size;
   index_type type_size;
 
+  if (source->base_addr == NULL)
+    return NULL;
+
   type_size = GFC_DTYPE_TYPE_SIZE(source);
   size = GFC_DESCRIPTOR_SIZE (source);
   switch (type_size)
@@ -177,7 +178,7 @@ internal_pack (gfc_array_char * source)
     return source->base_addr;
 
    /* Allocate storage for the destination.  */
-  destptr = xmalloc (ssize * size);
+  destptr = xmallocarray (ssize, size);
   dest = (char *)destptr;
   src = source->base_addr;
   stride0 = stride[0] * size;