On 11/11/2013 06:37 PM, Paul Eggert wrote: > Pádraig Brady wrote: >> + static const char b64c[64] = >> + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; > ... >> + static const char b64c[64] = >> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; > > There only needs to be one copy of b64c.
Moved to module scope. >> + if ((inlen % 3 == 0) && BASE64_LENGTH (inlen) == outlen) > > This divides by 3 twice, once for % and once for BASE64_LENGTH, > and if we want to be truly paranoid it can mess up due to overflow, > e.g., on a 32-bit host if inlen == 2**32 - 1 && outlen == 0. > > How about this instead? > > if (outlen % 4 == 0 && inlen == outlen / 4 * 3) > > where any decent compiler should do the right thing and > generate only shifts, masks, and adds; and there's no > problem with overflow. Ah right, reduce outlen to match inlen. thanks! Pádraig.