From e1894f0a0eb33eb27c80d88e35bc7cd5cf9f1e26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Thu, 1 Jan 2015 21:02:31 +0100 Subject: [PATCH] Silent a signed-comparison warning in Base-64 decoding The sizeof() is used to compute a number of members of a static array. The unsigned (size_t) value was then used to compare against a signed value. And here compiler can warn. To prevent from pointless sign extension to size_t width, I decided to store the "constant" (it's 80) into int8_t as it fits there. --- src/cdecode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cdecode.c b/src/cdecode.c index 6eba8bd..a245dac 100644 --- a/src/cdecode.c +++ b/src/cdecode.c @@ -20,7 +20,8 @@ static int8_t base64_decode_value(int8_t value_in) { 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; - static const size_t decoding_size = sizeof(decoding)/sizeof(*decoding); + /* The value is 80, so it fits into int8_t. */ + static const int8_t decoding_size = sizeof(decoding)/sizeof(*decoding); value_in -= 43; if (value_in < 0 || value_in >= decoding_size) return -1; return decoding[value_in]; -- 2.11.4.GIT