Skip to content

Commit 5e9e884

Browse files
author
Thomas G. Lockhart
committed
Automatically promote out of range integers to floats.
Throw elog(NOTICE) to flag promotion.
1 parent 9e22f82 commit 5e9e884

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

src/backend/parser/scan.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* A lexical scanner generated by flex */
22

33
/* Scanner skeleton version:
4-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.11 1998/02/02 00:03:39 scrappy Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.12 1998/02/11 03:56:08 thomas Exp $
55
*/
66

77
#define FLEX_SCANNER
@@ -539,7 +539,7 @@ char *yytext;
539539
*
540540
*
541541
* IDENTIFICATION
542-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.11 1998/02/02 00:03:39 scrappy Exp $
542+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.12 1998/02/11 03:56:08 thomas Exp $
543543
*
544544
*-------------------------------------------------------------------------
545545
*/
@@ -1159,41 +1159,57 @@ YY_RULE_SETUP
11591159
errno = 0;
11601160
yylval.ival = strtol((char *)yytext,&endptr,10);
11611161
if (*endptr != '\0' || errno == ERANGE)
1162-
elog(ERROR,"Bad integer input '%s'",yytext);
1162+
{
1163+
errno = 0;
1164+
yylval.dval = strtod(((char *)yytext),&endptr);
1165+
if (*endptr != '\0' || errno == ERANGE)
1166+
elog(ERROR,"Bad integer input '%s'",yytext);
1167+
CheckFloat8Val(yylval.dval);
1168+
elog(NOTICE,"Integer input '%s' is out of range; promoted to float", yytext);
1169+
return (FCONST);
1170+
}
11631171
return (ICONST);
11641172
}
11651173
YY_BREAK
11661174
case 34:
11671175
YY_RULE_SETUP
1168-
#line 324 "scan.l"
1176+
#line 332 "scan.l"
11691177
{
11701178
char* endptr;
11711179

11721180
BEGIN(xm);
11731181
errno = 0;
11741182
yylval.dval = strtod(((char *)yytext),&endptr);
11751183
if (*endptr != '\0' || errno == ERANGE)
1176-
elog(ERROR,"Bad float8 input '%s'",yytext);
1184+
elog(ERROR,"Bad float8 input '%s'",yytext);
11771185
CheckFloat8Val(yylval.dval);
11781186
return (FCONST);
11791187
}
11801188
YY_BREAK
11811189
case 35:
11821190
YY_RULE_SETUP
1183-
#line 335 "scan.l"
1191+
#line 343 "scan.l"
11841192
{
11851193
char* endptr;
11861194

11871195
errno = 0;
11881196
yylval.ival = strtol((char *)yytext,&endptr,10);
11891197
if (*endptr != '\0' || errno == ERANGE)
1190-
elog(ERROR,"Bad integer input '%s'",yytext);
1198+
{
1199+
errno = 0;
1200+
yylval.dval = strtod(((char *)yytext),&endptr);
1201+
if (*endptr != '\0' || errno == ERANGE)
1202+
elog(ERROR,"Bad integer input '%s'",yytext);
1203+
CheckFloat8Val(yylval.dval);
1204+
elog(NOTICE,"Integer input '%s' is out of range; promoted to float", yytext);
1205+
return (FCONST);
1206+
}
11911207
return (ICONST);
11921208
}
11931209
YY_BREAK
11941210
case 36:
11951211
YY_RULE_SETUP
1196-
#line 344 "scan.l"
1212+
#line 360 "scan.l"
11971213
{
11981214
char* endptr;
11991215

@@ -1207,7 +1223,7 @@ YY_RULE_SETUP
12071223
YY_BREAK
12081224
case 37:
12091225
YY_RULE_SETUP
1210-
#line 354 "scan.l"
1226+
#line 370 "scan.l"
12111227
{
12121228
int i;
12131229
ScanKeyword *keyword;
@@ -1229,20 +1245,20 @@ YY_RULE_SETUP
12291245
YY_BREAK
12301246
case 38:
12311247
YY_RULE_SETUP
1232-
#line 372 "scan.l"
1248+
#line 388 "scan.l"
12331249
{ /* ignore */ }
12341250
YY_BREAK
12351251
case 39:
12361252
YY_RULE_SETUP
1237-
#line 374 "scan.l"
1253+
#line 390 "scan.l"
12381254
{ return (yytext[0]); }
12391255
YY_BREAK
12401256
case 40:
12411257
YY_RULE_SETUP
1242-
#line 376 "scan.l"
1258+
#line 392 "scan.l"
12431259
ECHO;
12441260
YY_BREAK
1245-
#line 1246 "lex.yy.c"
1261+
#line 1262 "lex.yy.c"
12461262
case YY_STATE_EOF(INITIAL):
12471263
case YY_STATE_EOF(xb):
12481264
case YY_STATE_EOF(xc):
@@ -2128,7 +2144,7 @@ int main()
21282144
return 0;
21292145
}
21302146
#endif
2131-
#line 376 "scan.l"
2147+
#line 392 "scan.l"
21322148

21332149

21342150
void yyerror(char message[])

src/backend/parser/scan.l

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.34 1998/01/05 16:39:19 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.35 1998/02/11 03:56:07 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -318,7 +318,15 @@ other .
318318
errno = 0;
319319
yylval.ival = strtol((char *)yytext,&endptr,10);
320320
if (*endptr != '\0' || errno == ERANGE)
321-
elog(ERROR,"Bad integer input '%s'",yytext);
321+
{
322+
errno = 0;
323+
yylval.dval = strtod(((char *)yytext),&endptr);
324+
if (*endptr != '\0' || errno == ERANGE)
325+
elog(ERROR,"Bad integer input '%s'",yytext);
326+
CheckFloat8Val(yylval.dval);
327+
elog(NOTICE,"Integer input '%s' is out of range; promoted to float", yytext);
328+
return (FCONST);
329+
}
322330
return (ICONST);
323331
}
324332
{real}/{space}*-{number} {
@@ -328,7 +336,7 @@ other .
328336
errno = 0;
329337
yylval.dval = strtod(((char *)yytext),&endptr);
330338
if (*endptr != '\0' || errno == ERANGE)
331-
elog(ERROR,"Bad float8 input '%s'",yytext);
339+
elog(ERROR,"Bad float8 input '%s'",yytext);
332340
CheckFloat8Val(yylval.dval);
333341
return (FCONST);
334342
}
@@ -338,7 +346,15 @@ other .
338346
errno = 0;
339347
yylval.ival = strtol((char *)yytext,&endptr,10);
340348
if (*endptr != '\0' || errno == ERANGE)
341-
elog(ERROR,"Bad integer input '%s'",yytext);
349+
{
350+
errno = 0;
351+
yylval.dval = strtod(((char *)yytext),&endptr);
352+
if (*endptr != '\0' || errno == ERANGE)
353+
elog(ERROR,"Bad integer input '%s'",yytext);
354+
CheckFloat8Val(yylval.dval);
355+
elog(NOTICE,"Integer input '%s' is out of range; promoted to float", yytext);
356+
return (FCONST);
357+
}
342358
return (ICONST);
343359
}
344360
{real} {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy