Consistently pass an "unsigned char" to ctype.h functions.
authorNoah Misch <noah@leadboat.com>
Sun, 6 Jul 2014 04:29:51 +0000 (00:29 -0400)
committerNoah Misch <noah@leadboat.com>
Sun, 6 Jul 2014 04:29:51 +0000 (00:29 -0400)
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
src/backend/utils/adt/json.c

index 2906ccbf8c8f7c8074c8f738c97a1d86c5107ff1..13c95a2e2e90c081b3d496c3705c00fb78ccb86a 100644 (file)
@@ -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");
index 841dd1aeae2f720cc69a4f76a4ec2952462347fd..bc0c602fa3e487ca6e7fb3aef8aa7561e3c55235 100644 (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, "\\\\");