]> Sergey Matveev's repositories - st.git/commit
base64_digits: reduce scope, implicit zero, +1 size
authorNRK <nrk@disroot.org>
Fri, 18 Mar 2022 11:03:34 +0000 (17:03 +0600)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Fri, 18 Mar 2022 11:20:27 +0000 (12:20 +0100)
commitef0551932fb162f907b40185d2f48c3b497708ee
tree7051a47cfe413c345ca707d3550be21e00081556
parentaf3bb68add1c40d19d0dee382009e21b0870a38f
base64_digits: reduce scope, implicit zero, +1 size

the array is not accessed outside of base64dec() so it makes sense to
limit it's scope to the related function. the static-storage duration of
the array is kept intact.

this also removes unnecessary explicit zeroing from the start and end of
the array. anything that wasn't explicitly zero-ed will now be
implicitly zero-ed instead.

the validity of the new array can be easily confirmed via running this
trivial loop:

for (int i = 0; i < 255; ++i)
assert(base64_digits[i] == base64_digits_old[i]);

lastly, as pointed out by Roberto, the array needs to have 256 elements
in order to able access it as any unsigned char as an index; the
previous array had 255.

however, this array will only be accessed at indexes which are
isprint() || '=' (see `base64dec_getc()`), so reducing the size of the
array to the highest printable ascii char (127 AFAIK) + 1 might also be
a valid strategy.
st.c