util: Add function hexits_value() for parsing multiple hex digits.
[sliver-openvswitch.git] / lib / json.c
index 5887f67..0a8bca2 100644 (file)
@@ -746,19 +746,15 @@ json_lex_number(struct json_parser *p)
 static const char *
 json_lex_4hex(const char *cp, const char *end, int *valuep)
 {
-    int value, i;
+    unsigned int value;
 
     if (cp + 4 > end) {
         return "quoted string ends within \\u escape";
     }
 
-    value = 0;
-    for (i = 0; i < 4; i++) {
-        unsigned char c = *cp++;
-        if (!isxdigit(c)) {
-            return "malformed \\u escape";
-        }
-        value = (value << 4) | hexit_value(c);
+    value = hexits_value(cp, 4, NULL);
+    if (value == UINT_MAX) {
+        return "malformed \\u escape";
     }
     if (!value) {
         return "null bytes not supported in quoted strings";