[ovs-dev] [PATCH 14/17] util: Make hexits_value() support 64-bit integers too.

Ben Pfaff blp at nicira.com
Wed Sep 17 05:57:07 UTC 2014


Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/json.c     |  5 +++--
 lib/nx-match.c |  7 +++++--
 lib/util.c     | 20 ++++++++------------
 lib/util.h     |  2 +-
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/lib/json.c b/lib/json.c
index 9c819d7..8114972 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -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) {
diff --git a/lib/nx-match.c b/lib/nx-match.c
index df39b4e..5970e44 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -1093,8 +1093,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;
         }
     }
diff --git a/lib/util.c b/lib/util.c
index 01e8a0e..1528aef 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -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;
 }
 
diff --git a/lib/util.h b/lib/util.h
index ea9bcfa..60cd9db 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -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);
 
-- 
1.9.1




More information about the dev mailing list