Signed-off-by: Ben Pfaff <b...@nicira.com> --- v1->v2: Fix inverted check in parse_nxm_field_name(). --- 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 ef25641..63f06dd 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -1089,8 +1089,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.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev