postgres.git / summary / log / commit / refs

commit    333b7db8b39679acf0665b3fc4ad99cbc14fbba7
Author:   Noah Misch <noah@leadboat.com>
Date:     Sun Jul 06 04:29:51 2014 +0000

    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.


contrib/pg_upgrade/controldata.c | 2 +- src/backend/utils/adt/json.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/contrib/pg_upgrade/controldata.c b/contrib/pg_upgrade/controldata.c index 2906ccbf8c8..13c95a2e2e9 100644 --- a/contrib/pg_upgrade/controldata.c +++ b/contrib/pg_upgrade/controldata.c @@ -154,7 +154,7 @@ get_control_data(ClusterInfo *cluster, bool live_check) if (GET_MAJOR_VERSION(cluster->major_version) <= 803) { for (p = bufin; *p; p++) - if (!isascii(*p)) + if (!isascii((unsigned char) *p)) pg_fatal("The 8.3 cluster's pg_controldata is incapable of outputting ASCII, even\n" "with LANG=C. You must upgrade this cluster to a newer version of PostgreSQL\n" "8.3 to fix this bug. PostgreSQL 8.3.7 and later are known to work properly.\n"); diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c index 841dd1aeae2..bc0c602fa3e 100644 --- a/src/backend/utils/adt/json.c +++ b/src/backend/utils/adt/json.c @@ -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, "\\\\"); [parent: e254ff21d128]