OSDN Git Service

PR 43839
[pf3gnuchains/gcc-fork.git] / libgfortran / io / format.c
index 97bd2da..5771777 100644 (file)
@@ -1,9 +1,9 @@
-/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Andy Vaught
    F2003 I/O support contributed by Jerry DeLisle
 
-This file is part of the GNU Fortran 95 runtime library (libgfortran).
+This file is part of the GNU Fortran runtime library (libgfortran).
 
 Libgfortran is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -29,9 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
  * interpretation during I/O statements */
 
 #include "io.h"
+#include "format.h"
 #include <ctype.h>
 #include <string.h>
 #include <stdbool.h>
+#include <stdlib.h>
 
 #define FARRAY_SIZE 64
 
@@ -89,7 +91,7 @@ free_format_hash_table (gfc_unit *u)
       if (u->format_hash_table[i].hashed_fmt != NULL)
        {
          free_format_data (u->format_hash_table[i].hashed_fmt);
-         free_mem (u->format_hash_table[i].key);
+         free (u->format_hash_table[i].key);
        }
       u->format_hash_table[i].key = NULL;
       u->format_hash_table[i].key_len = 0;      
@@ -129,7 +131,7 @@ reset_fnode_counters (st_parameter_dt *dtp)
   /* Clear this pointer at the head so things start at the right place.  */
   fmt->array.array[0].current = NULL;
 
-  for (f = fmt->last->array[0].u.child; f; f = f->next)
+  for (f = fmt->array.array[0].u.child; f; f = f->next)
     reset_node (f);
 }
 
@@ -170,7 +172,7 @@ save_parsed_format (st_parameter_dt *dtp)
   u->format_hash_table[hash].hashed_fmt = NULL;
 
   if (u->format_hash_table[hash].key != NULL)
-    free_mem (u->format_hash_table[hash].key);
+    free (u->format_hash_table[hash].key);
   u->format_hash_table[hash].key = get_mem (dtp->format_len);
   memcpy (u->format_hash_table[hash].key, dtp->format, dtp->format_len);
 
@@ -281,10 +283,10 @@ free_format_data (format_data *fmt)
   for (fa = fmt->array.next; fa; fa = fa_next)
     {
       fa_next = fa->next;
-      free_mem (fa);
+      free (fa);
     }
 
-  free_mem (fmt);
+  free (fmt);
   fmt = NULL;
 }
 
@@ -706,7 +708,8 @@ parse_format_list (st_parameter_dt *dtp, bool *save_ok)
          goto data_desc;
        }
 
-      if (t != FMT_COMMA && t != FMT_RPAREN && t != FMT_SLASH)
+      if (t != FMT_COMMA && t != FMT_RPAREN && t != FMT_SLASH
+         && t != FMT_POSINT)
        {
          fmt->error = "Comma required after P descriptor";
          goto finished;
@@ -861,7 +864,7 @@ parse_format_list (st_parameter_dt *dtp, bool *save_ok)
       t = format_lex (fmt);
       if (t != FMT_POSINT)
        {
-         if (notification_std(GFC_STD_GNU) == ERROR)
+         if (notification_std(GFC_STD_GNU) == NOTIFICATION_ERROR)
            {
              fmt->error = posint_required;
              goto finished;
@@ -910,7 +913,7 @@ parse_format_list (st_parameter_dt *dtp, bool *save_ok)
       u = format_lex (fmt);
       if (t == FMT_G && u == FMT_ZERO)
        {
-         if (notification_std (GFC_STD_F2008) == ERROR
+         if (notification_std (GFC_STD_F2008) == NOTIFICATION_ERROR
              || dtp->u.p.mode == READING)
            {
              fmt->error = zero_width;
@@ -1216,6 +1219,8 @@ parse_format (st_parameter_dt *dtp)
   format_data *fmt;
   bool format_cache_ok;
 
+  /* Don't cache for internal units and set an arbitrary limit on the size of
+     format strings we will cache.  (Avoids memory issues.)  */
   format_cache_ok = !is_internal_unit (dtp);
 
   /* Lookup format string to see if it has already been parsed.  */