1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Consistently pass an "unsigned char" to ctype.h functions.

The isxdigit() calls relied on undefined behavior.  The isascii() call
was well-defined, but our prevailing style is to include the cast.
Back-patch to 9.4, where the isxdigit() calls were introduced.
This commit is contained in:
Noah Misch
2014-07-06 00:29:51 -04:00
parent e254ff21d1
commit 333b7db8b3
2 changed files with 6 additions and 3 deletions

View File

@ -2353,8 +2353,11 @@ escape_json(StringInfo buf, const char *str)
* only unicode escape that should be present is \u0000,
* all the other unicode escapes will have been resolved.
*/
if (p[1] == 'u' && isxdigit(p[2]) && isxdigit(p[3])
&& isxdigit(p[4]) && isxdigit(p[5]))
if (p[1] == 'u' &&
isxdigit((unsigned char) p[2]) &&
isxdigit((unsigned char) p[3]) &&
isxdigit((unsigned char) p[4]) &&
isxdigit((unsigned char) p[5]))
appendStringInfoCharMacro(buf, *p);
else
appendStringInfoString(buf, "\\\\");