From d80b9b477774b0e783f943cd86334ca64b9a477b Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Fri, 29 Mar 2013 10:37:37 +0100 Subject: re PR libfortran/56737 (Wrong I/O result with format cache for Hollerith strings) 2013-03-29 Tobias Burnus PR fortran/56737 * io/format.c (parse_format): With caching, copy dtp->format string. (save_parsed_format): Use dtp->format directy without copying. 2013-03-29 Tobias Burnus PR fortran/56737 * testsuite/gfortran.dg/fmt_cache_3.f90: New. (Plus: Move fortran/ChangeLog item to libgfortran/ChangeLog) From-SVN: r197229 --- libgfortran/io/format.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libgfortran/io') diff --git a/libgfortran/io/format.c b/libgfortran/io/format.c index c64596b..db95e49 100644 --- a/libgfortran/io/format.c +++ b/libgfortran/io/format.c @@ -148,8 +148,7 @@ save_parsed_format (st_parameter_dt *dtp) u->format_hash_table[hash].hashed_fmt = NULL; free (u->format_hash_table[hash].key); - u->format_hash_table[hash].key = xmalloc (dtp->format_len); - memcpy (u->format_hash_table[hash].key, dtp->format, dtp->format_len); + u->format_hash_table[hash].key = dtp->format; u->format_hash_table[hash].key_len = dtp->format_len; u->format_hash_table[hash].hashed_fmt = dtp->u.p.fmt; @@ -1223,6 +1222,13 @@ parse_format (st_parameter_dt *dtp) /* Not found so proceed as follows. */ + if (format_cache_ok) + { + char *fmt_string = xmalloc (dtp->format_len); + memcpy (fmt_string, dtp->format, dtp->format_len); + dtp->format = fmt_string; + } + dtp->u.p.fmt = fmt = xmalloc (sizeof (format_data)); fmt->format_string = dtp->format; fmt->format_string_len = dtp->format_len; @@ -1257,6 +1263,8 @@ parse_format (st_parameter_dt *dtp) if (fmt->error) { format_error (dtp, NULL, fmt->error); + if (format_cache_ok) + free (dtp->format); free_format_hash_table (dtp->u.p.current_unit); return; } -- cgit v1.1