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) {
/* 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;
}
}
}
/* 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;
}
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);