[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bison glr skeleton SIGSEGV-avoiding patch
From: |
Tim Van Holder |
Subject: |
Re: bison glr skeleton SIGSEGV-avoiding patch |
Date: |
18 Mar 2003 15:03:26 +0100 |
On Tue, 2003-03-18 at 14:11, Miroslav Tichy wrote:
> Then an issue concerning sizeof("string")
> it seemed that the correct meaning was strlen("string"),
> not sizeof(char *).
Actually sizeof("string") is neither strlen("string") nor sizeof(char*)
- it corresponds to n where n is the number of bytes used by the string
literal including the terminating NUL.
This as opposed to strlen, which counts characters until the _first_ NUL
(cfr sizeof("blah\0blah") <-> strlen("blah\0blah")).
In the case below, using strlen() instead of sizeof introduces a memory
allocation bug - with sizeof, a place is reserved for the closing NUL of
the new string, with strlen() there isn't. There's also a small
performance penalty for using strlen() instead of sizeof.
> - yysize += (sizeof ("syntax error, unexpected ")
> + yysize += (strlen ("syntax error, unexpected ")
> + strlen (yytokenName (*yytokenp)));
> yymsg = (char*) malloc (yysize);
BTW, you seem to have used a reverse diff - it is typical to compare the
original source to your changed one (like cvs diff does) so that your
changes show up as additions, not removals. I adjusted the diff snippet
above to use the 'typical' notation.
--
Tim Van Holder <address@hidden>