diff options
author | Kamen Mazdrashki <kamen.mazdrashki@postpath.com> | 2009-09-25 23:40:55 +0300 |
---|---|---|
committer | Matthias Dieter Wallnöfer <mwallnoefer@yahoo.de> | 2009-10-01 23:12:58 +0200 |
commit | 8330d78b2126ac072d9c7abb146d1f8a8bf91844 (patch) | |
tree | f3c729f8e202018f8933d54e7ccf49b5d17bd595 | |
parent | 154ab0b0472e1519b18936e8a14edb7ff689120f (diff) | |
download | samba-8330d78b2126ac072d9c7abb146d1f8a8bf91844.tar.gz samba-8330d78b2126ac072d9c7abb146d1f8a8bf91844.tar.bz2 samba-8330d78b2126ac072d9c7abb146d1f8a8bf91844.zip |
util: strhex_to_str() fixed to handle '0x' correctly
-rw-r--r-- | lib/util/util.c | 12 |
1 files 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; |