Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit965a3d6

Browse files
committed
Fix realfailN lexer rules to not make assumptions about input format.
The realfail1 and realfail2 backup-prevention rules always returnedtoken type FCONST, ignoring the possibility that what we've scannedis more appropriately described as ICONST. I think that at thetime that code was added, it might actually have been safe to notdistinguish; but since we started allowing AS-less aliases in SELECTtarget lists, it's definitely legal to have a number immediatelyfollowed by an identifier.In the SELECT case, it seems there's no visible consequence becausemake_const() will change the type back to integer anyway. But I'mworried that there are other contexts, or will be in future, whereit's more important to get the constant's type right.Hence, use process_integer_literal to correctly determine whichtoken type to return.Arguably this is a bug fix, but given the lack of evidence ofuser-visible problems, I'll refrain from back-patching.Discussion:https://postgr.es/m/21364.1542136808@sss.pgh.pa.us
1 parent4766bcd commit965a3d6

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

‎src/backend/parser/scan.l

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,22 +1005,18 @@ other.
10051005
}
10061006
{realfail1}{
10071007
/*
1008-
* throw back the [Ee], and treat as {decimal}. Note
1009-
* that it is possible the input is actually {integer},
1010-
* but since this case will almost certainly lead to a
1011-
* syntax error anyway, we don't bother to distinguish.
1008+
* throw back the [Ee], and figure out whether what
1009+
* remains is an {integer} or {decimal}.
10121010
*/
10131011
yyless(yyleng -1);
10141012
SET_YYLLOC();
1015-
yylval->str =pstrdup(yytext);
1016-
return FCONST;
1013+
returnprocess_integer_literal(yytext, yylval);
10171014
}
10181015
{realfail2}{
10191016
/* throw back the [Ee][+-], and proceed as above */
10201017
yyless(yyleng -2);
10211018
SET_YYLLOC();
1022-
yylval->str =pstrdup(yytext);
1023-
return FCONST;
1019+
returnprocess_integer_literal(yytext, yylval);
10241020
}
10251021

10261022

@@ -1255,6 +1251,10 @@ litbufdup(core_yyscan_t yyscanner)
12551251
returnnew;
12561252
}
12571253

1254+
/*
1255+
* Process {integer}. Note this will also do the right thing with {decimal},
1256+
* ie digits and a decimal point.
1257+
*/
12581258
staticint
12591259
process_integer_literal(constchar *token, YYSTYPE *lval)
12601260
{
@@ -1265,7 +1265,7 @@ process_integer_literal(const char *token, YYSTYPE *lval)
12651265
val =strtoint(token, &endptr,10);
12661266
if (*endptr !='\0' || errno == ERANGE)
12671267
{
1268-
/* integer too large, treat it as a float */
1268+
/* integer too large (or contains decimal pt), treat it as a float */
12691269
lval->str =pstrdup(token);
12701270
return FCONST;
12711271
}

‎src/fe_utils/psqlscan.l

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,9 @@ other.
887887
}
888888
{realfail1}{
889889
/*
890-
* throw back the [Ee], and treat as {decimal}. Note
891-
* that it is possible the input is actually {integer},
892-
* but since this case will almost certainly lead to a
893-
* syntax error anyway, we don't bother to distinguish.
890+
* throw back the [Ee], and figure out whether what
891+
* remains is an {integer} or {decimal}.
892+
* (in psql, we don't actually care...)
894893
*/
895894
yyless(yyleng -1);
896895
ECHO;

‎src/interfaces/ecpg/preproc/pgc.l

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -900,20 +900,16 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
900900
}
901901
{realfail1}{
902902
/*
903-
* throw back the [Ee], and treat as {decimal}. Note
904-
* that it is possible the input is actually {integer},
905-
* but since this case will almost certainly lead to a
906-
* syntax error anyway, we don't bother to distinguish.
903+
* throw back the [Ee], and figure out whether what
904+
* remains is an {integer} or {decimal}.
907905
*/
908906
yyless(yyleng -1);
909-
base_yylval.str =mm_strdup(yytext);
910-
return FCONST;
907+
returnprocess_integer_literal(yytext, &base_yylval);
911908
}
912909
{realfail2}{
913910
/* throw back the [Ee][+-], and proceed as above */
914911
yyless(yyleng -2);
915-
base_yylval.str =mm_strdup(yytext);
916-
return FCONST;
912+
returnprocess_integer_literal(yytext, &base_yylval);
917913
}
918914
}/* <C,SQL> */
919915

@@ -1473,6 +1469,10 @@ addlitchar(unsigned char ychar)
14731469
literalbuf[literallen] ='\0';
14741470
}
14751471

1472+
/*
1473+
* Process {integer}. Note this will also do the right thing with {decimal},
1474+
* ie digits and a decimal point.
1475+
*/
14761476
staticint
14771477
process_integer_literal(constchar *token, YYSTYPE *lval)
14781478
{
@@ -1483,7 +1483,7 @@ process_integer_literal(const char *token, YYSTYPE *lval)
14831483
val =strtoint(token, &endptr,10);
14841484
if (*endptr !='\0' || errno == ERANGE)
14851485
{
1486-
/* integer too large, treat it as a float */
1486+
/* integer too large (or contains decimal pt), treat it as a float */
14871487
lval->str =mm_strdup(token);
14881488
return FCONST;
14891489
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp