chiark / gitweb /
Allow space for terminating null in struct glyph.data
GCC 15 gives a warning (-Wunterminated-string-initialization) if you
initialize an unsigned char array from a string constant such that the
terminating null character isn't included. Bedstead does this in most
rows of the glyphs array, which is quite noisy. I've chosen to work
around this by making the array one byte larger. That doesn't
actually affect the size of the struct on systems that align struct
fields, so the major loss is that now we might not get warnings if we
overflow by one byte.
There are several other ways this problem could be solved. One could
disable the warning entirely, but that would remove a valuable warning
from the rest of the program. We currently disable two other warnings
for the sake of the glyphs array, but working around them would
require ugly changes on every line of the array.
Probably the ideal approach would be to tag the "data" field with
"[[gnu::nonstring]]". That would not only suppress the warning but
also enable warnings if the array was ever passed to a function
expecting a null-terminated string. However, I think Bedstead is
currently written in plain ISO C99, while attributes like that were
only standardised in C23. I'm not averse to moving to a newer
standard, but C23 is a but _too_ new right now. I'm also a little
reluctant to rely on the implementation-defined behaviour of
particular compilers, which is why I'm not using "#pragma GCC
diagnostic".