This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/31922] Accessing uninitialized variable for print *, trim(blank_string)
- From: "jvdelisle at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 May 2007 02:38:44 -0000
- Subject: [Bug fortran/31922] Accessing uninitialized variable for print *, trim(blank_string)
- References: <bug-31922-13404@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from jvdelisle at gcc dot gnu dot org 2007-05-15 03:38 -------
I think the correct place to fix this is in trim. The uninitialized variable
is being passed to the library from trim. Looking at the fdump-tree-original,
you can see that the variable ch is initialized by setting to all blanks. Then
a temporary char pointer is set up to pass to trim which is called with a
temporary len which is set by trim to zero when it scans through the string of
blanks.
This patch fixes this.
Index: string_intrinsics.c
===================================================================
*** string_intrinsics.c (revision 124646)
--- string_intrinsics.c (working copy)
*************** string_trim (GFC_INTEGER_4 * len, void *
*** 171,176 ****
--- 171,178 ----
/* copy string if necessary. */
memmove (*dest, src, *len);
}
+ else
+ *dest = NULL;
}
With this patch, valgrind gives a clean report and it regression tested fine.
I also checked the result of the same operation to a file.
I will commit this to trunk as simple and obvious if you agree.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31922