jwerle / b64.c

Base64 encode/decode
MIT License
269 stars 103 forks source link

char passed to isalpha, must be int #22

Open ashesman opened 4 years ago

ashesman commented 4 years ago

Line 44 of decode.c

if (!(isalnum(src[j]) || '+' == src[j] || '/' == src[j])) { break; }

Should be

if (!(isalnum(**(int)**src[j]) || '+' == src[j] || '/' == src[j])) { break; }

Otherwise an error: array subscript has type 'char' [-Werror=char-subscripts] occurs. Referring to GCC 9s ctype.h:

/ These macros are intentionally written in a manner that will trigger a gcc -Wall warning if the user mistakenly passes a 'char' instead of an int containing an 'unsigned char'. Note that the sizeof will always be 1, which is what we want for mapping EOF to __CTYPE_PTR[0]; the use of a raw index inside the sizeof triggers the gcc warning if c was of type char, and sizeof masks side effects of the extra c. Meanwhile, the real index to __CTYPE_PTR+1 must be cast to int, since isalpha(0x100000001LL) must equal isalpha(1), rather than being an out-of-bounds reference on a 64-bit machine. /