jwerle / b64.c

Base64 encode/decode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

char passed to isalpha, must be int

ashesman opened this issue · comments

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. */