chiark / gitweb /
Allow space for terminating null in struct glyph.data
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 16 Nov 2025 13:22:36 +0000 (13:22 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 13 Jan 2026 21:55:10 +0000 (21:55 +0000)
commit36d6f142e1dd97e00d02caf3412bb6f3f0fc7a57
treebe8437dca1df23540fc6b7bc1959949c0021ab6f
parent557685b3d06a721551f372ea8c56aa607b1e4d7e
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".
bedstead.c