Skip to content

Commit 196a6ca

Browse files
committed
Fix unportable use of isxdigit() with char (rather than unsigned char)
argument, per warnings from buildfarm member pika. Also clean up code formatting a trifle.
1 parent e319e67 commit 196a6ca

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/backend/parser/scan.l

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
2626
* IDENTIFICATION
27-
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.165 2010/01/02 16:57:50 momjian Exp $
27+
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.166 2010/01/16 17:39:55 tgl Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -1137,7 +1137,7 @@ process_integer_literal(const char *token, YYSTYPE *lval)
11371137
return ICONST;
11381138
}
11391139

1140-
static int
1140+
static unsigned int
11411141
hexval(unsigned char c)
11421142
{
11431143
if (c >= '0' && c <= '9')
@@ -1194,7 +1194,7 @@ addunicode(pg_wchar c, core_yyscan_t yyscanner)
11941194
yyerror("Unicode escape values cannot be used for code point values above 007F when the server encoding is not UTF8");
11951195
yyextra->saw_non_ascii = true;
11961196
}
1197-
unicode_to_utf8(c, (unsigned char *)buf);
1197+
unicode_to_utf8(c, (unsigned char *) buf);
11981198
addlit(buf, pg_mblen(buf), yyscanner);
11991199
}
12001200

@@ -1241,9 +1241,17 @@ litbuf_udeescape(unsigned char escape, core_yyscan_t yyscanner)
12411241
*out++ = escape;
12421242
in += 2;
12431243
}
1244-
else if (isxdigit(in[1]) && isxdigit(in[2]) && isxdigit(in[3]) && isxdigit(in[4]))
1244+
else if (isxdigit((unsigned char) in[1]) &&
1245+
isxdigit((unsigned char) in[2]) &&
1246+
isxdigit((unsigned char) in[3]) &&
1247+
isxdigit((unsigned char) in[4]))
12451248
{
1246-
pg_wchar unicode = hexval(in[1]) * 16*16*16 + hexval(in[2]) * 16*16 + hexval(in[3]) * 16 + hexval(in[4]);
1249+
pg_wchar unicode;
1250+
1251+
unicode = (hexval(in[1]) << 12) +
1252+
(hexval(in[2]) << 8) +
1253+
(hexval(in[3]) << 4) +
1254+
hexval(in[4]);
12471255
check_unicode_value(unicode, in, yyscanner);
12481256
if (pair_first)
12491257
{
@@ -1270,13 +1278,22 @@ litbuf_udeescape(unsigned char escape, core_yyscan_t yyscanner)
12701278
}
12711279
in += 5;
12721280
}
1273-
else if (in[1] == '+'
1274-
&& isxdigit(in[2]) && isxdigit(in[3])
1275-
&& isxdigit(in[4]) && isxdigit(in[5])
1276-
&& isxdigit(in[6]) && isxdigit(in[7]))
1281+
else if (in[1] == '+' &&
1282+
isxdigit((unsigned char) in[2]) &&
1283+
isxdigit((unsigned char) in[3]) &&
1284+
isxdigit((unsigned char) in[4]) &&
1285+
isxdigit((unsigned char) in[5]) &&
1286+
isxdigit((unsigned char) in[6]) &&
1287+
isxdigit((unsigned char) in[7]))
12771288
{
1278-
pg_wchar unicode = hexval(in[2]) * 16*16*16*16*16 + hexval(in[3]) * 16*16*16*16 + hexval(in[4]) * 16*16*16
1279-
+ hexval(in[5]) * 16*16 + hexval(in[6]) * 16 + hexval(in[7]);
1289+
pg_wchar unicode;
1290+
1291+
unicode = (hexval(in[2]) << 20) +
1292+
(hexval(in[3]) << 16) +
1293+
(hexval(in[4]) << 12) +
1294+
(hexval(in[5]) << 8) +
1295+
(hexval(in[6]) << 4) +
1296+
hexval(in[7]);
12801297
check_unicode_value(unicode, in, yyscanner);
12811298
if (pair_first)
12821299
{

0 commit comments

Comments
 (0)