This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Cpp memory corruption in gcc 3.3
On Thu, Oct 23, 2003 at 04:38:45PM -0700, H. J. Lu wrote:
> On Thu, Oct 23, 2003 at 02:05:41PM -0700, Zack Weinberg wrote:
> > "H. J. Lu" <hjl@lucon.org> writes:
> >
> > > I have a very strange cpp memory corruption in gcc 3.3 on Linux/ia64
> > > running RHEL 3. I got
> > >
> > > Old value = 42983
> > > New value = 30064814055
> > > _cpp_lex_direct (pfile=0x60000000000fdcc0)
> > > at /net/gnu/export/gnu/src/gcc-3.3/gcc/gcc/cpplex.c:972
> > > 972 result->col = CPP_BUF_COLUMN (buffer, buffer->cur);
> > > (gdb)
> > >
> > > It overrides some memory in malloc. Any ideas?
> >
> > Provide a test case.
> >
>
> There are so many files involved. However this patch seems to work
> for me on my testcase. The problem is pfile->cur_token was advanced
> beyond what was returned by alloc_expansion_token. Does that make any
> senses?
>
This is not correct. I will keep looking.
H.J.
> H.J.
> ----
> 2003-10-23 H.J. Lu <hongjiu.lu@intel.com>
>
> * cppmacro.c (lex_expansion_token): Save and restore cur_token.
>
> --- gcc/cppmacro.c.memory 2003-07-07 14:44:29.000000000 -0700
> +++ gcc/cppmacro.c 2003-10-23 16:29:16.000000000 -0700
> @@ -1426,7 +1426,7 @@ lex_expansion_token (pfile, macro)
> cpp_reader *pfile;
> cpp_macro *macro;
> {
> - cpp_token *token;
> + cpp_token *token, *saved_cur_token = pfile->cur_token;
>
> pfile->cur_token = alloc_expansion_token (pfile, macro);
> token = _cpp_lex_direct (pfile);
> @@ -1441,6 +1441,7 @@ lex_expansion_token (pfile, macro)
> && (token->type == CPP_STRING || token->type == CPP_CHAR))
> check_trad_stringification (pfile, macro, &token->val.str);
>
> + pfile->cur_token = saved_cur_token;
> return token;
> }
>