From 8330d78b2126ac072d9c7abb146d1f8a8bf91844 Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Fri, 25 Sep 2009 23:40:55 +0300 Subject: util: strhex_to_str() fixed to handle '0x' correctly --- lib/util/util.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/util/util.c b/lib/util/util.c index a07f50ae3b..fd0e6b8d79 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -579,18 +579,18 @@ _PUBLIC_ _PURE_ size_t count_chars(const char *s, char c) **/ _PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t strhex_len) { - size_t i; + size_t i = 0; size_t num_chars = 0; uint8_t lonybble, hinybble; const char *hexchars = "0123456789ABCDEF"; char *p1 = NULL, *p2 = NULL; - for (i = 0; i < strhex_len && strhex[i] != 0; i++) { - if (strncasecmp(hexchars, "0x", 2) == 0) { - i++; /* skip two chars */ - continue; - } + /* skip leading 0x prefix */ + if (strncasecmp(strhex, "0x", 2) == 0) { + i += 2; /* skip two chars */ + } + for (; i < strhex_len && strhex[i] != 0; i++) { if (!(p1 = strchr(hexchars, toupper((unsigned char)strhex[i])))) break; -- cgit