Merge branch 'hex2nibble'

This commit is contained in:
Daniel Eklöf 2021-01-04 08:32:31 +01:00
commit b4d7a60864
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

14
uri.c
View file

@ -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;