From a3bd06cb68754fc296cbaaca2d7ec4b2d38e9034 Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Wed, 19 Aug 2015 00:09:43 +0200 Subject: [PATCH] lib: use proper unsigned type for walking string Use a pointer to unsigned char as the type of variable to walk the string and write the output. Important since we know that character values can be over 127, and we use the value as an index into a 256-part array during decoding. After this change, we can also remove some ugly typecasts. --- lib/dec/head.c | 4 ++-- lib/dec/tail.c | 8 ++++---- lib/enc/head.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/dec/head.c b/lib/dec/head.c index 08cbb37a..f19b7958 100644 --- a/lib/dec/head.c +++ b/lib/dec/head.c @@ -1,6 +1,6 @@ int ret = 0; -const char *c = src; -char *o = out; +const unsigned char *c = (const unsigned char *)src; +unsigned char *o = (unsigned char *)out; unsigned char q; /* Use local temporaries to avoid cache thrashing: */ diff --git a/lib/dec/tail.c b/lib/dec/tail.c index efdfd482..f59fa7d9 100644 --- a/lib/dec/tail.c +++ b/lib/dec/tail.c @@ -2,7 +2,7 @@ ret = 1; break; } - if ((q = base64_table_dec[(unsigned char)*c++]) >= 254) { + if ((q = base64_table_dec[*c++]) >= 254) { st.eof = 1; /* Treat character '=' as invalid for byte 0: */ break; @@ -14,7 +14,7 @@ ret = 1; break; } - if ((q = base64_table_dec[(unsigned char)*c++]) >= 254) { + if ((q = base64_table_dec[*c++]) >= 254) { st.eof = 1; /* Treat character '=' as invalid for byte 1: */ break; @@ -28,7 +28,7 @@ ret = 1; break; } - if ((q = base64_table_dec[(unsigned char)*c++]) >= 254) { + if ((q = base64_table_dec[*c++]) >= 254) { st.eof = 1; /* When q == 254, the input char is '='. Return 1 and EOF. * Technically, should check if next byte is also '=', but never mind. @@ -45,7 +45,7 @@ ret = 1; break; } - if ((q = base64_table_dec[(unsigned char)*c++]) >= 254) { + if ((q = base64_table_dec[*c++]) >= 254) { st.eof = 1; /* When q == 254, the input char is '='. Return 1 and EOF. * When q == 255, the input char is invalid. Return 0 and EOF. */ diff --git a/lib/enc/head.c b/lib/enc/head.c index f586822d..36dda07d 100644 --- a/lib/enc/head.c +++ b/lib/enc/head.c @@ -1,7 +1,7 @@ /* Assume that *out is large enough to contain the output. * Theoretically it should be 4/3 the length of src. */ -const unsigned char *c = (unsigned char *)src; -char *o = out; +const unsigned char *c = (const unsigned char *)src; +unsigned char *o = (unsigned char *)out; /* Use local temporaries to avoid cache thrashing: */ size_t outl = 0;