mirror of
https://github.com/openvswitch/ovs
synced 2025-09-02 07:15:17 +00:00
util: Make hexits_value() support 64-bit integers too.
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
16
lib/util.c
16
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;
|
||||
return UINTMAX_MAX;
|
||||
}
|
||||
value = (value << 4) + hexit;
|
||||
}
|
||||
if (ok) {
|
||||
*ok = true;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user