aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-04 07:32:31 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-04 07:32:31 +0000
commitb4d7a60864d351164340a8dd7b135bf5b06de4cd (patch)
treec93cb7052a7e2abd7c0367a427a7775d94d36ea8
parentMerge branch 'blank-before-trailing-comment' (diff)
parenturi: rename nibbletohex() function to hex2nibble() (diff)
Merge branch 'hex2nibble'
-rw-r--r--uri.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/uri.c b/uri.c
index 31bbc7b6..a0e3838a 100644
--- a/uri.c
+++ b/uri.c
@@ -2,7 +2,6 @@
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
#include <limits.h>
#include <unistd.h>
#include <assert.h>
@@ -12,8 +11,12 @@
#include "log.h"
#include "xmalloc.h"
+enum {
+ HEX_DIGIT_INVALID = 16
+};
+
static uint8_t
-nibble2hex(char c)
+hex2nibble(char c)
{
switch (c) {
case '0': case '1': case '2': case '3': case '4':
@@ -27,8 +30,7 @@ nibble2hex(char c)
return c - 'A' + 10;
}
- assert(false);
- return 0;
+ return HEX_DIGIT_INVALID;
}
bool
@@ -199,8 +201,8 @@ uri_parse(const char *uri, size_t len,
encoded_len -= prefix_len;
decoded_len += prefix_len;
- if (isxdigit(next[1]) && isxdigit(next[2])) {
- *p++ = nibble2hex(next[1]) << 4 | nibble2hex(next[2]);
+ if (hex2nibble(next[1]) <= 15 && hex2nibble(next[2]) <= 15) {
+ *p++ = hex2nibble(next[1]) << 4 | hex2nibble(next[2]);
decoded_len++;
encoded_len -= 3;
encoded = next + 3;