]> git.proxmox.com Git - ovs.git/commitdiff
util: Make hexits_value() support 64-bit integers too.
authorBen Pfaff <blp@nicira.com>
Tue, 30 Sep 2014 19:45:50 +0000 (12:45 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 8 Oct 2014 21:47:22 +0000 (14:47 -0700)
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
lib/json.c
lib/nx-match.c
lib/util.c
lib/util.h

index 9c819d7ff7491cc4aa1c9f1695cc894d0fd0edad..811497292bd333cc181724d4b5f922eed5654897 100644 (file)
@@ -746,13 +746,14 @@ static const char *
 json_lex_4hex(const char *cp, const char *end, int *valuep)
 {
     unsigned int value;
+    bool ok;
 
     if (cp + 4 > end) {
         return "quoted string ends within \\u escape";
     }
 
-    value = hexits_value(cp, 4, NULL);
-    if (value == UINT_MAX) {
+    value = hexits_value(cp, 4, &ok);
+    if (!ok) {
         return "malformed \\u escape";
     }
     if (!value) {
index 0563a7b3a959186f75d220108d13b0479d7f40d9..de062eb30715c536cf3231bc946b29f4655affe9 100644 (file)
@@ -1097,8 +1097,11 @@ parse_nxm_field_name(const char *name, int name_len)
     /* Check whether it's a 32-bit field header value as hex.
      * (This isn't ordinarily useful except for testing error behavior.) */
     if (name_len == 8) {
-        uint32_t header = hexits_value(name, name_len, NULL);
-        if (header != UINT_MAX) {
+        uint32_t header;
+        bool ok;
+
+        header = hexits_value(name, name_len, &ok);
+        if (ok) {
             return header;
         }
     }
index 707c652ac50f3536ea2b96e33a5ee4b170172926..fb2ff51bdfaacca08dc0c7ac0e84ea2a86247c13 100644 (file)
@@ -701,29 +701,25 @@ hexit_value(int c)
 }
 
 /* Returns the integer value of the 'n' hexadecimal digits starting at 's', or
- * UINT_MAX if one of those "digits" is not really a hex digit.  If 'ok' is
- * nonnull, '*ok' is set to true if the conversion succeeds or to false if a
- * non-hex digit is detected. */
-unsigned int
+ * UINTMAX_MAX if one of those "digits" is not really a hex digit.  Sets '*ok'
+ * to true if the conversion succeeds or to false if a non-hex digit is
+ * detected. */
+uintmax_t
 hexits_value(const char *s, size_t n, bool *ok)
 {
-    unsigned int value;
+    uintmax_t value;
     size_t i;
 
     value = 0;
     for (i = 0; i < n; i++) {
         int hexit = hexit_value(s[i]);
         if (hexit < 0) {
-            if (ok) {
-                *ok = false;
-            }
-            return UINT_MAX;
+            *ok = false;
+            return UINTMAX_MAX;
         }
         value = (value << 4) + hexit;
     }
-    if (ok) {
-        *ok = true;
-    }
+    *ok = true;
     return value;
 }
 
index d3e64691e9033e410fe90eeecf69177d11b2d121..f171dbfc6cd2738b8041d39043de67fc09674352 100644 (file)
@@ -319,7 +319,7 @@ bool ovs_scan(const char *s, const char *format, ...) SCANF_FORMAT(2, 3);
 bool str_to_double(const char *, double *);
 
 int hexit_value(int c);
-unsigned int hexits_value(const char *s, size_t n, bool *ok);
+uintmax_t hexits_value(const char *s, size_t n, bool *ok);
 
 const char *english_list_delimiter(size_t index, size_t total);