mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
uri: use nibble2hex() instead of isxdigit(3) to check valid hex digits
This commit is contained in:
parent
1004387223
commit
f22d4e9587
1 changed files with 6 additions and 4 deletions
10
uri.c
10
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,6 +11,10 @@
|
|||
#include "log.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
enum {
|
||||
HEX_DIGIT_INVALID = 16
|
||||
};
|
||||
|
||||
static uint8_t
|
||||
nibble2hex(char c)
|
||||
{
|
||||
|
|
@ -27,8 +30,7 @@ nibble2hex(char c)
|
|||
return c - 'A' + 10;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return 0;
|
||||
return HEX_DIGIT_INVALID;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -199,7 +201,7 @@ uri_parse(const char *uri, size_t len,
|
|||
encoded_len -= prefix_len;
|
||||
decoded_len += prefix_len;
|
||||
|
||||
if (isxdigit(next[1]) && isxdigit(next[2])) {
|
||||
if (nibble2hex(next[1]) <= 15 && nibble2hex(next[2]) <= 15) {
|
||||
*p++ = nibble2hex(next[1]) << 4 | nibble2hex(next[2]);
|
||||
decoded_len++;
|
||||
encoded_len -= 3;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue