Skip to content

Commit 3d4d1e1

Browse files
author
Thomas G. Lockhart
committed
Implement SQL92 binary and hexadecimal string decoding (b'10' and x'1F').
Check decoding of integer in x - y syntax (already done for most ints).
1 parent 2fa3302 commit 3d4d1e1

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/backend/parser/scan.l

Lines changed: 64 additions & 2 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.28 1997/11/14 15:43:27 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.29 1997/11/17 16:31:39 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -71,6 +71,8 @@ char literal[MAX_PARSE_BUFFER];
7171
* There are exclusive states for quoted strings, extended comments,
7272
* and to eliminate parsing troubles for numeric strings.
7373
* Exclusive states:
74+
* <xb> binary numeric string - thomas 1997-11-16
75+
* <xh> hexadecimal numeric string - thomas 1997-11-16
7476
* <xc> extended C-style comments - tgl 1997-07-12
7577
* <xq> quoted strings - tgl 1997-07-30
7678
* <xm> numeric strings with embedded minus sign - tgl 1997-09-05
@@ -83,8 +85,10 @@ char literal[MAX_PARSE_BUFFER];
8385
* operator-like symbols. - thomas 1997-07-14
8486
*/
8587

88+
%x xb
8689
%x xc
8790
%x xd
91+
%x xh
8892
%x xq
8993
%x xm
9094

@@ -97,6 +101,16 @@ xqembedded "\\'"
97101
xqliteral [\\](.|\n)
98102
xqcat {quote}{space}*\n{space}*{quote}
99103

104+
xbstart [bB]{quote}
105+
xbstop {quote}
106+
xbinside [^']*
107+
xbcat {quote}{space}*\n{space}*{quote}
108+
109+
xhstart [xX]{quote}
110+
xhstop {quote}
111+
xhinside [^']*
112+
xhcat {quote}{space}*\n{space}*{quote}
113+
100114
dquote \"
101115
xdstart {dquote}
102116
xdstop {dquote}
@@ -162,6 +176,48 @@ other .
162176

163177
<xc>{xcinside} { /* ignore */ }
164178

179+
{xbstart} {
180+
BEGIN(xb);
181+
llen = 0;
182+
*literal = '\0';
183+
}
184+
<xb>{xbstop} {
185+
char* endptr;
186+
187+
BEGIN(INITIAL);
188+
errno = 0;
189+
yylval.ival = strtol((char *)literal,&endptr,2);
190+
if (*endptr != '\0' || errno == ERANGE)
191+
elog(WARN,"Bad binary integer input '%s'",literal);
192+
return (ICONST);
193+
}
194+
<xh>{xhinside} |
195+
<xb>{xbinside} {
196+
if ((llen+yyleng) > (MAX_PARSE_BUFFER - 1))
197+
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
198+
memcpy(literal+llen, yytext, yyleng+1);
199+
llen += yyleng;
200+
}
201+
<xh>{xhcat} |
202+
<xb>{xbcat} {
203+
}
204+
205+
{xhstart} {
206+
BEGIN(xh);
207+
llen = 0;
208+
*literal = '\0';
209+
}
210+
<xh>{xhstop} {
211+
char* endptr;
212+
213+
BEGIN(INITIAL);
214+
errno = 0;
215+
yylval.ival = strtol((char *)literal,&endptr,16);
216+
if (*endptr != '\0' || errno == ERANGE)
217+
elog(WARN,"Bad hexadecimal integer input '%s'",literal);
218+
return (ICONST);
219+
}
220+
165221
{xqstart} {
166222
BEGIN(xq);
167223
llen = 0;
@@ -250,12 +306,18 @@ other .
250306
}
251307

252308
{integer}/{space}*-{number} {
309+
char* endptr;
310+
253311
BEGIN(xm);
254-
yylval.ival = atoi((char*)yytext);
312+
errno = 0;
313+
yylval.ival = strtol((char *)yytext,&endptr,10);
314+
if (*endptr != '\0' || errno == ERANGE)
315+
elog(WARN,"Bad integer input '%s'",yytext);
255316
return (ICONST);
256317
}
257318
{real}/{space}*-{number} {
258319
char* endptr;
320+
259321
BEGIN(xm);
260322
errno = 0;
261323
yylval.dval = strtod(((char *)yytext),&endptr);

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