re PR fortran/85520 (Out of memory when declaring a character with len << 0)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Tue, 24 Apr 2018 23:17:29 +0000 (23:17 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Tue, 24 Apr 2018 23:17:29 +0000 (23:17 +0000)
2018-04-24  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/85520
* decl.c (gfc_match_char_spec): Check for negative length and set to 0.

2018-04-24  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/85520
* gfortran.dg/pr85520.f90: New test.

From-SVN: r259623

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr85520.f90 [new file with mode: 0644]

index 9d126868cc9ea6536e7a21726335b9b5c46185ac..46c234fdab9cb1dd77ff3c2c3281fdd0a93c7c79 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-24  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/85520
+       * decl.c (gfc_match_char_spec): Check for negative length and set to 0.
+
 2018-04-14  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        PR fortran/81773
index 192910dfe65984d1f3e032425d53b328f233ebea..d1b75ccd54c750f0fbf7f9bdd3ade01deaca56eb 100644 (file)
@@ -3235,7 +3235,11 @@ done:
          e = gfc_copy_expr (len);
          gfc_reduce_init_expr (e);
          if (e->expr_type == EXPR_CONSTANT)
-           gfc_replace_expr (len, e);
+           {
+             gfc_replace_expr (len, e);
+             if (mpz_cmp_si (len->value.integer, 0) < 0)
+               mpz_set_ui (len->value.integer, 0);
+           }
          else
            gfc_free_expr (e);
          cl->length = len;
index ff4b5fbe28384717d6b94e62e4fbffccb181325f..6ba8fede06b111d709cdbd4e26626c3d3a3a5e1f 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-24  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/85520
+       * gfortran.dg/pr85520.f90: New test.
+
 2018-04-24  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR target/85512
diff --git a/gcc/testsuite/gfortran.dg/pr85520.f90 b/gcc/testsuite/gfortran.dg/pr85520.f90
new file mode 100644 (file)
index 0000000..3e66a90
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do run }
+! PR fortran/85520
+! Original code from Gerhard Steinmetz <gscfq at t-online dot de>
+program p
+   character(-huge(1)) :: c = ' '
+    if (len(c) /= 0) stop 1
+end