From 36d6f142e1dd97e00d02caf3412bb6f3f0fc7a57 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sun, 16 Nov 2025 13:22:36 +0000 Subject: [PATCH] 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bedstead.c b/bedstead.c index 88934eb..8f96e0b 100644 --- a/bedstead.c +++ b/bedstead.c @@ -215,8 +215,13 @@ static struct weight const *weight = &weights[0]; static struct glyph { union { - /* Top row (and left column) don't appear in ROM. */ - unsigned char data[YSIZE - 1]; + /* + * Top row (and left column) don't appear in ROM. But + * we allow an extra byte so that string constants can + * write a terminating null. Without that, GCC 15 + * generates a warning that the string might be + * unterminated. */ + unsigned char data[YSIZE - 1 + 1]; char const *alias_of; int subr_idx; }; -- 2.30.2