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.
This commit is contained in:
Tom Lane 2010-01-16 17:39:55 +00:00
parent e319e6799a
commit 196a6ca5de

View File

@ -24,7 +24,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.165 2010/01/02 16:57:50 momjian Exp $ * $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.166 2010/01/16 17:39:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1137,7 +1137,7 @@ process_integer_literal(const char *token, YYSTYPE *lval)
return ICONST; return ICONST;
} }
static int static unsigned int
hexval(unsigned char c) hexval(unsigned char c)
{ {
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9')
@ -1194,7 +1194,7 @@ addunicode(pg_wchar c, core_yyscan_t yyscanner)
yyerror("Unicode escape values cannot be used for code point values above 007F when the server encoding is not UTF8"); yyerror("Unicode escape values cannot be used for code point values above 007F when the server encoding is not UTF8");
yyextra->saw_non_ascii = true; yyextra->saw_non_ascii = true;
} }
unicode_to_utf8(c, (unsigned char *)buf); unicode_to_utf8(c, (unsigned char *) buf);
addlit(buf, pg_mblen(buf), yyscanner); addlit(buf, pg_mblen(buf), yyscanner);
} }
@ -1241,9 +1241,17 @@ litbuf_udeescape(unsigned char escape, core_yyscan_t yyscanner)
*out++ = escape; *out++ = escape;
in += 2; in += 2;
} }
else if (isxdigit(in[1]) && isxdigit(in[2]) && isxdigit(in[3]) && isxdigit(in[4])) else if (isxdigit((unsigned char) in[1]) &&
isxdigit((unsigned char) in[2]) &&
isxdigit((unsigned char) in[3]) &&
isxdigit((unsigned char) in[4]))
{ {
pg_wchar unicode = hexval(in[1]) * 16*16*16 + hexval(in[2]) * 16*16 + hexval(in[3]) * 16 + hexval(in[4]); pg_wchar unicode;
unicode = (hexval(in[1]) << 12) +
(hexval(in[2]) << 8) +
(hexval(in[3]) << 4) +
hexval(in[4]);
check_unicode_value(unicode, in, yyscanner); check_unicode_value(unicode, in, yyscanner);
if (pair_first) if (pair_first)
{ {
@ -1270,13 +1278,22 @@ litbuf_udeescape(unsigned char escape, core_yyscan_t yyscanner)
} }
in += 5; in += 5;
} }
else if (in[1] == '+' else if (in[1] == '+' &&
&& isxdigit(in[2]) && isxdigit(in[3]) isxdigit((unsigned char) in[2]) &&
&& isxdigit(in[4]) && isxdigit(in[5]) isxdigit((unsigned char) in[3]) &&
&& isxdigit(in[6]) && isxdigit(in[7])) isxdigit((unsigned char) in[4]) &&
isxdigit((unsigned char) in[5]) &&
isxdigit((unsigned char) in[6]) &&
isxdigit((unsigned char) in[7]))
{ {
pg_wchar unicode = hexval(in[2]) * 16*16*16*16*16 + hexval(in[3]) * 16*16*16*16 + hexval(in[4]) * 16*16*16 pg_wchar unicode;
+ hexval(in[5]) * 16*16 + hexval(in[6]) * 16 + hexval(in[7]);
unicode = (hexval(in[2]) << 20) +
(hexval(in[3]) << 16) +
(hexval(in[4]) << 12) +
(hexval(in[5]) << 8) +
(hexval(in[6]) << 4) +
hexval(in[7]);
check_unicode_value(unicode, in, yyscanner); check_unicode_value(unicode, in, yyscanner);
if (pair_first) if (pair_first)
{ {