re PR libfortran/61499 (Internal read of negative integer broken)
[gcc.git] / libgfortran / io / unit.c
index e522195e5dddc06954ea957b9848faab773b6441..22b315a4fd3d3e2144b99bc701b82c7e4d5ff591 100644 (file)
@@ -382,9 +382,7 @@ static bool
 is_trim_ok (st_parameter_dt *dtp)
 {
   /* Check rank and stride.  */
-  if (dtp->internal_unit_desc
-      && (GFC_DESCRIPTOR_RANK (dtp->internal_unit_desc) > 1
-         || GFC_DESCRIPTOR_STRIDE(dtp->internal_unit_desc, 0) != 1))
+  if (dtp->internal_unit_desc)
     return false;
   /* Format strings can not have 'BZ' or '/'.  */
   if (dtp->common.flags & IOPARM_DT_HAS_FORMAT)
@@ -456,7 +454,7 @@ get_internal_unit (st_parameter_dt *dtp)
     {
       iunit->rank = GFC_DESCRIPTOR_RANK (dtp->internal_unit_desc);
       iunit->ls = (array_loop_spec *)
-       xmalloc (iunit->rank * sizeof (array_loop_spec));
+       xmallocarray (iunit->rank, sizeof (array_loop_spec));
       dtp->internal_unit_len *=
        init_loop_spec (dtp->internal_unit_desc, iunit->ls, &start_record);
 
@@ -788,7 +786,6 @@ unit_truncate (gfc_unit * u, gfc_offset pos, st_parameter_common * common)
 char *
 filename_from_unit (int n)
 {
-  char *filename;
   gfc_unit *u;
   int c;
 
@@ -807,11 +804,7 @@ filename_from_unit (int n)
 
   /* Get the filename.  */
   if (u != NULL)
-    {
-      filename = (char *) xmalloc (u->file_len + 1);
-      unpack_filename (filename, u->file, u->file_len);
-      return filename;
-    }
+    return fc_strdup (u->file, u->file_len);
   else
     return (char *) NULL;
 }