From 32099fdef1852782ed37f50a40261ce3967d7fbc Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sat, 23 Mar 2019 02:38:01 +0100 Subject: [PATCH] avoid ctype toupper - libc toupper is locale dependent - removes the dependency on ctype.h --- bn_mp_read_radix.c | 4 +++- tommath_private.h | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bn_mp_read_radix.c b/bn_mp_read_radix.c index 1179b7b5d..5c3a5c6ad 100644 --- a/bn_mp_read_radix.c +++ b/bn_mp_read_radix.c @@ -12,6 +12,8 @@ * SPDX-License-Identifier: Unlicense */ +#define MP_TOUPPER(c) ((c) >= 'a' && (c) <= 'z' ? (c) + 'A' - 'a' : (c)) + /* read a string [ASCII] in a given radix */ int mp_read_radix(mp_int *a, const char *str, int radix) { @@ -46,7 +48,7 @@ int mp_read_radix(mp_int *a, const char *str, int radix) * this allows numbers like 1AB and 1ab to represent the same value * [e.g. in hex] */ - ch = (radix <= 36) ? (char)toupper((int)*str) : *str; + ch = (radix <= 36) ? (char)MP_TOUPPER((int)*str) : *str; pos = (unsigned)(ch - '('); if (mp_s_rmap_reverse_sz < pos) { break; diff --git a/tommath_private.h b/tommath_private.h index ecd3447c1..7d62c1ea4 100644 --- a/tommath_private.h +++ b/tommath_private.h @@ -13,7 +13,6 @@ #define TOMMATH_PRIV_H_ #include "tommath.h" -#include #ifndef MIN #define MIN(x, y) (((x) < (y)) ? (x) : (y))