From 938dcaa450a66969dcee090ebebdf384c6592799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Fri, 21 Apr 2017 18:56:52 +0200 Subject: [PATCH] Avoid any assumptions about the signedness of char. --- lib/enc/cryb_base32_decode.c | 9 +++++---- lib/enc/cryb_base64_decode.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/enc/cryb_base32_decode.c b/lib/enc/cryb_base32_decode.c index c7cc061..47b0f87 100644 --- a/lib/enc/cryb_base32_decode.c +++ b/lib/enc/cryb_base32_decode.c @@ -36,7 +36,7 @@ #include -static const char b32dec[256] = { +static const uint8_t b32dec[256] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -87,8 +87,9 @@ static const char b32dec[256] = { * excess data, but returns the total amount. */ int -base32_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen) +base32_decode(const char *cin, size_t ilen, uint8_t *out, size_t *olen) { + const uint8_t *in = (const uint8_t *)cin; size_t len; int bits, shift, padding; @@ -97,10 +98,10 @@ base32_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen) (padding && *in == '=')) { /* consume */ continue; - } else if (!padding && b32dec[(uint8_t)*in] >= 0) { + } else if (!padding && b32dec[*in] != 0xff) { /* shift into accumulator */ shift += 5; - bits = bits << 5 | b32dec[(uint8_t)*in]; + bits = bits << 5 | b32dec[*in]; } else if (!padding && *in == '=' && (shift == 1 || shift == 2 || shift == 3 || shift == 4)) { /* final byte */ diff --git a/lib/enc/cryb_base64_decode.c b/lib/enc/cryb_base64_decode.c index d4a6b38..0e1d7b3 100644 --- a/lib/enc/cryb_base64_decode.c +++ b/lib/enc/cryb_base64_decode.c @@ -36,7 +36,7 @@ #include -static const char b64dec[256] = { +static const uint8_t b64dec[256] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -87,8 +87,9 @@ static const char b64dec[256] = { * excess data, but returns the total amount. */ int -base64_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen) +base64_decode(const char *cin, size_t ilen, uint8_t *out, size_t *olen) { + const uint8_t *in = (const uint8_t *)cin; size_t len; int bits, shift, padding; @@ -97,10 +98,10 @@ base64_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen) (padding && *in == '=')) { /* consume */ continue; - } else if (!padding && b64dec[(uint8_t)*in] >= 0) { + } else if (!padding && b64dec[*in] != 0xff) { /* shift into accumulator */ shift += 6; - bits = bits << 6 | b64dec[(uint8_t)*in]; + bits = bits << 6 | b64dec[*in]; } else if (!padding && *in == '=' && (shift == 2 || shift == 4)) { /* final byte */