Re: A really subtle lexer bug
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: pgsql-hackers@postgresql.org
Date: 2018-08-23T19:05:53Z
Lists: pgsql-hackers
Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
> Here's what I will push unless there's something important I missed.
Stylistic nitpick: I don't especially like "continue" as the body of
a for-loop. How about instead of this:
for (nchars--;
nchars > 1 &&
(yytext[nchars - 1] == '+' ||
yytext[nchars - 1] == '-');
nchars--)
continue;
do this:
do {
nchars--;
} while (nchars > 1 &&
(yytext[nchars - 1] == '+' ||
yytext[nchars - 1] == '-'));
That's a clearer separation between loop action and loop test, and
it makes it more obvious that you're relying on the loop condition
to be true at the start.
Also, I'm not entirely convinced that replacing the strchr() with
a handmade equivalent is a good idea. Some versions of strchr()
are pretty quick.
No objections beyond that.
regards, tom lane
Commits
-
Fix lexing of standard multi-character operators in edge cases.
- d64fad666992 10.6 landed
- 5b4555f90c08 11.0 landed
- a40631a920ac 12.0 landed
- af988d13012f 9.5.15 landed
- 5ec70a928621 9.6.11 landed