>From c212c47bc8ce70ac8252281ebd49e7bbd22a3b63 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Wed, 1 Nov 2017 18:49:14 -0500 Subject: [PATCH] ip6_addr: convert xchar to lwip_xchar This converts the xchar macro to a static lwip_xchar function xchar is not part of any standard C library that we can determine and this code must have only been building when ctype.h was not in the include tree (thus xchar was always defined since #ifndef isprint was always true) --- src/core/ipv6/ip6_addr.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/core/ipv6/ip6_addr.c b/src/core/ipv6/ip6_addr.c index 56a21ceb..2e29a8a5 100644 --- a/src/core/ipv6/ip6_addr.c +++ b/src/core/ipv6/ip6_addr.c @@ -57,9 +57,20 @@ const ip_addr_t ip6_addr_any = IPADDR6_INIT(0ul, 0ul, 0ul, 0ul); #define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F')) #define islower(c) in_range(c, 'a', 'z') #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') -#define xchar(i) ((char)((i) < 10 ? '0' + (i) : 'A' + (i) - 10)) #endif +/** + * Converts hex to uppercase ascii equivalent + * + * @param i hex value + * @return ascii equivalent + */ +static char +lwip_xchar(int i) +{ + return (char)(i < 10 ? '0' + i : 'A' + i - 10); +} + /** * Check whether "cp" is a valid ascii representation * of an IPv6 address and convert to a binary address. @@ -252,7 +263,7 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) if ((current_block_value & 0xf000) == 0) { zero_flag = 1; } else { - buf[i++] = xchar(((current_block_value & 0xf000) >> 12)); + buf[i++] = lwip_xchar((current_block_value & 0xf000) >> 12); zero_flag = 0; if (i >= buflen) { return NULL; @@ -262,7 +273,7 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) if (((current_block_value & 0xf00) == 0) && (zero_flag)) { /* do nothing */ } else { - buf[i++] = xchar(((current_block_value & 0xf00) >> 8)); + buf[i++] = lwip_xchar((current_block_value & 0xf00) >> 8); zero_flag = 0; if (i >= buflen) { return NULL; @@ -273,14 +284,14 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) /* do nothing */ } else { - buf[i++] = xchar(((current_block_value & 0xf0) >> 4)); + buf[i++] = lwip_xchar((current_block_value & 0xf0) >> 4); zero_flag = 0; if (i >= buflen) { return NULL; } } - buf[i++] = xchar((current_block_value & 0xf)); + buf[i++] = lwip_xchar(current_block_value & 0xf); if (i >= buflen) { return NULL; } -- 2.14.1