This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch,fortran,committed] Fixed memory allocation in expr.c for 4.2 [PR29713] (was: Re: make check: Regressions on trunk and 4.2)
- From: Tobias Burnus <burnus at net-b dot de>
- To: Tobias Burnus <burnus at net-b dot de>
- Cc: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>
- Date: Thu, 09 Nov 2006 15:40:52 +0100
- Subject: [patch,fortran,committed] Fixed memory allocation in expr.c for 4.2 [PR29713] (was: Re: make check: Regressions on trunk and 4.2)
- References: <4552FED5.6090408@net-b.de> <45531BE1.6040106@net-b.de> <45532310.80402@net-b.de>
Hi,
Tobias Burnus wrote:
>> Line 744 of gcc-4_2-branch/gcc/fortran/decl.c is function
>> gfc_set_constant_character_len:
>>
>> gfc_free (expr->value.character.string);
>>
>> This looks good in principle and also matches 4.3. Any ideas what goes
>> wrong here?
>>
I should trust valgrind more and do no step-wise debugging in gdb with
"-O2".
The problem is PR29713, which I found on the trunk and which FX nicely
debugged and fixed
(but unfortunately only on the trunk).
I somehow believed that this was fixed in GCC 4.2 in the meanwhile
(especially since gfc_set_constant_character_len looked the same). But
of cause the problem was in gfc_simplify_expr as valgrind told me.
I followed FX by submitting it as obvious. (Since the testcase is
already in gcc, I didn't included a reduced testcase.)
Same fix needs to be done for 4.1 as
http://gcc.gnu.org/viewcvs/branches/gcc-4_1-branch/gcc/fortran/expr.c?view=markup
shows.
Tobias
--- branches/gcc-4_2-branch/gcc/fortran/expr.c 2006/11/09 10:26:10 118619
+++ branches/gcc-4_2-branch/gcc/fortran/expr.c 2006/11/09 14:28:59 118620
@@ -1485,7 +1485,7 @@
gfc_extract_int (p->ref->u.ss.start, &start);
start--; /* Convert from one-based to zero-based. */
gfc_extract_int (p->ref->u.ss.end, &end);
- s = gfc_getmem (end - start + 1);
+ s = gfc_getmem (end - start + 2);
memcpy (s, p->value.character.string + start, end - start);
s[end-start+1] = '\0'; /* TODO: C-style string for debugging. */
gfc_free (p->value.character.string);