This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/31922] Accessing uninitialized variable for print *, trim(blank_string)



------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]