#136 yyless() macro arg not parenthesized

2.5.35
closed-invalid
nobody
5
2012-04-27
2012-04-10
Jens
No

The yyless(n) macro replacement text does not parenthesize the argument n.
This can lead to compile errors for valid code.

tokenizer.l:
119 char *dollar;
120
121 if ((dollar = memchr (yytext, '$', yyleng)) != NULL) {
122 yyless (dollar - yytext); /* Leaves the non-$ part. */

$ gcc -Wall -std=c99 -g -pedantic tokenizer.c -o tokenizer
tokenizer.l: In function 'yylex':
tokenizer.l:122: error: invalid operands to binary +

Using extra parentheses as in

yyless((dollar - yytext))

fixes the problem. But that is just a workaround. The bug is that flex should parenthesize ALL arguments of ALL function-like macros,
at least the user-visible ones like, yyless, unput, and some of the YY macros.
Just imagine what the effect of using low precedence operators like ?: in those macros is...
Thanks!

PS: The comment above the yyless macro should read
"into a single C statement" instead of
"int a single C statement"

Discussion

  • Jens

    Jens - 2012-04-10

    This is on FreeBSD 9, and it appears that the FreeBSD folks use a modified skeleton. If that turns out to be true, I'll fix it for FreeBSD.

     
  • Jens

    Jens - 2012-04-11

    I've checked the flex.skl in 2.5.35 and the one used for /usr/bin/flex in FreeBSD.
    No problem in 2.5.35, but in FreeBSD. I've committed a fix to FreeBSD.
    You can close this report as a false alarm. Sorry for the noise, guys!

     
  • Will Estes

    Will Estes - 2012-04-27
    • status: open --> closed-invalid
     
  • Will Estes

    Will Estes - 2012-04-27

    Thanks for your interest in flex and for letting the FreeBSD folks know of the fix for this problem.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks