* [Bug fortran/31922] Accessing uninitialized variable for print *, trim(blank_string)
2007-05-14 18:25 [Bug fortran/31922] New: Accessing uninitialized variable for print *, trim(blank_string) burnus at gcc dot gnu dot org
@ 2007-05-14 19:24 ` burnus at gcc dot gnu dot org
2007-05-15 2:38 ` jvdelisle at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-05-14 19:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from burnus at gcc dot gnu dot org 2007-05-14 20:24 -------
Jerry, you are one of the libgfortran/IO experts, could you have a look?
_gfortran_transfer_character (&dt_parm.0, pstr.1, len.2);
uses uninitialized memory if len = 0 and p = NULL. This happens because
empty_string is not initialized to anything and points to a random position.
However, it is later tested for "p == NULL".
transfer_character (st_parameter_dt *dtp, void *p, int len)
{
static char *empty_string[0];
[..]
if (len == 0 && p == NULL)
p = empty_string;
dtp->u.p.transfer (dtp, BT_CHARACTER, p, len, len, 1);
And in:
formatted_transfer_scalar (st_parameter_dt *dtp, bt type, void *p, int len,
n = (p == NULL) ? 0 : ((type != BT_COMPLEX) ? 1 : 2);
Would be the following a correctly working alternative?
static char empty_string[0];
if (len == 0 && p == NULL)
p = &empty_string;
--
burnus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jvdelisle at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31922
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/31922] Accessing uninitialized variable for print *, trim(blank_string)
2007-05-14 18:25 [Bug fortran/31922] New: Accessing uninitialized variable for print *, trim(blank_string) burnus at gcc dot gnu dot org
2007-05-14 19:24 ` [Bug fortran/31922] " burnus at gcc dot gnu dot org
@ 2007-05-15 2:38 ` jvdelisle at gcc dot gnu dot org
2007-05-15 7:52 ` burnus at gcc dot gnu dot org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-05-15 2:38 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/31922] Accessing uninitialized variable for print *, trim(blank_string)
2007-05-14 18:25 [Bug fortran/31922] New: Accessing uninitialized variable for print *, trim(blank_string) burnus at gcc dot gnu dot org
2007-05-14 19:24 ` [Bug fortran/31922] " burnus at gcc dot gnu dot org
2007-05-15 2:38 ` jvdelisle at gcc dot gnu dot org
@ 2007-05-15 7:52 ` burnus at gcc dot gnu dot org
2007-05-16 0:38 ` jvdelisle at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-05-15 7:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from burnus at gcc dot gnu dot org 2007-05-15 08:52 -------
> This patch fixes this.
> + else
> + *dest = NULL;
This patch fixes the actual problem and should be committed. Thanks Jerry.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31922
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/31922] Accessing uninitialized variable for print *, trim(blank_string)
2007-05-14 18:25 [Bug fortran/31922] New: Accessing uninitialized variable for print *, trim(blank_string) burnus at gcc dot gnu dot org
` (2 preceding siblings ...)
2007-05-15 7:52 ` burnus at gcc dot gnu dot org
@ 2007-05-16 0:38 ` jvdelisle at gcc dot gnu dot org
2007-05-16 0:40 ` [Bug fortran/31922] [4.2 only] " jvdelisle at gcc dot gnu dot org
2007-05-20 23:00 ` jvdelisle at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-05-16 0:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from jvdelisle at gcc dot gnu dot org 2007-05-16 01:38 -------
Subject: Bug 31922
Author: jvdelisle
Date: Wed May 16 00:37:55 2007
New Revision: 124754
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124754
Log:
2007-05-15 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/31922
* intrinsics/string_intrinsics.c (string_trim): Set result to null if
string length is zero.
Modified:
trunk/libgfortran/ChangeLog
trunk/libgfortran/intrinsics/string_intrinsics.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31922
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/31922] [4.2 only] Accessing uninitialized variable for print *, trim(blank_string)
2007-05-14 18:25 [Bug fortran/31922] New: Accessing uninitialized variable for print *, trim(blank_string) burnus at gcc dot gnu dot org
` (3 preceding siblings ...)
2007-05-16 0:38 ` jvdelisle at gcc dot gnu dot org
@ 2007-05-16 0:40 ` jvdelisle at gcc dot gnu dot org
2007-05-20 23:00 ` jvdelisle at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-05-16 0:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from jvdelisle at gcc dot gnu dot org 2007-05-16 01:39 -------
Fixed on trunk
--
jvdelisle at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jvdelisle at gcc dot gnu dot
|dot org |org
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-05-16 01:39:55
date| |
Summary|Accessing uninitialized |[4.2 only] Accessing
|variable for print *, |uninitialized variable for
|trim(blank_string) |print *, trim(blank_string)
Target Milestone|--- |4.2.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31922
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/31922] [4.2 only] Accessing uninitialized variable for print *, trim(blank_string)
2007-05-14 18:25 [Bug fortran/31922] New: Accessing uninitialized variable for print *, trim(blank_string) burnus at gcc dot gnu dot org
` (4 preceding siblings ...)
2007-05-16 0:40 ` [Bug fortran/31922] [4.2 only] " jvdelisle at gcc dot gnu dot org
@ 2007-05-20 23:00 ` jvdelisle at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-05-20 23:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from jvdelisle at gcc dot gnu dot org 2007-05-21 00:00 -------
This is not a regression from previous releases. Closing.
--
jvdelisle at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31922
^ permalink raw reply [flat|nested] 7+ messages in thread