From 41ddbbea976d5873b13befd0d47ae42ec4f721b8 Mon Sep 17 00:00:00 2001 From: Massimiliano Pinto Date: Mon, 24 Jun 2013 13:43:01 +0200 Subject: [PATCH] Fixed gw_hex2bin: problems calling char_val. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we want tu use a compact implementation, we should use static inline uint8 char_val(uint8 X) {  return (uint) (X >= '0' && X <= '9' ? X-'0' :      X >= 'A' && X <= 'Z' ? X-'A'+10 : X-'a'+10); } --- core/utils.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/utils.c b/core/utils.c index f9c7773a7..3edd6c4e9 100644 --- a/core/utils.c +++ b/core/utils.c @@ -703,8 +703,13 @@ int gw_hex2bin(uint8_t *out, const char *in, unsigned int len) { } while (in < in_end) { - register char tmp_ptr = char_val(*in++); - *out++= (tmp_ptr << 4) | char_val(*in++); + register unsigned char b1 = char_val(*in); + uint8_t b2 = 0; + in++; + b2 = (b1 << 4) | char_val(*in); + *out++ = b2; + + in++; } return 0;