summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2021-01-14 10:21:19 +0100
committerJeremy Allison <jra@samba.org>2021-01-22 19:54:37 +0000
commitc5c9406b6098cddbb939b3abc5d9435a9a24f6b2 (patch)
tree3c26d99a71d1b3fd0748db115125e8fce3a13e39 /lib/util
parent7d0981f5e78bc881ca6521932379c69604c33a38 (diff)
downloadsamba-c5c9406b6098cddbb939b3abc5d9435a9a24f6b2.tar.gz
lib: Use hex_byte() in strhex_to_str()
I had completely missed that one in the last round... Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/util.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index 3ca6b61df32..57f19aaa1a1 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -879,42 +879,21 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t
{
size_t i = 0;
size_t num_chars = 0;
- uint8_t lonybble, hinybble;
- const char *hexchars = "0123456789ABCDEF";
- char *p1 = NULL, *p2 = NULL;
/* skip leading 0x prefix */
if (strncasecmp(strhex, "0x", 2) == 0) {
i += 2; /* skip two chars */
}
- for (; i+1 < strhex_len && strhex[i] != 0 && strhex[i+1] != 0; i++) {
- p1 = strchr(hexchars, toupper((unsigned char)strhex[i]));
- if (p1 == NULL) {
+ while ((i < strhex_len) && (num_chars < p_len)) {
+ bool ok = hex_byte(&strhex[i], (uint8_t *)&p[num_chars]);
+ if (!ok) {
break;
}
-
- i++; /* next hex digit */
-
- p2 = strchr(hexchars, toupper((unsigned char)strhex[i]));
- if (p2 == NULL) {
- break;
- }
-
- /* get the two nybbles */
- hinybble = PTR_DIFF(p1, hexchars);
- lonybble = PTR_DIFF(p2, hexchars);
-
- if (num_chars >= p_len) {
- break;
- }
-
- p[num_chars] = (hinybble << 4) | lonybble;
- num_chars++;
-
- p1 = NULL;
- p2 = NULL;
+ i += 2;
+ num_chars += 1;
}
+
return num_chars;
}