Skip to content

Fix build failure on GCC 15+: string literals truncating array NUL terminators - #13

Open
alvarop wants to merge 3 commits into
ADSBexchange:masterfrom
alvarop:fix-spinner-array-truncation
Open

alvarop wants to merge 3 commits into
ADSBexchange:masterfrom
alvarop:fix-spinner-array-truncation

Conversation

@alvarop

@alvarop alvarop commented Aug 1, 2026

Copy link
Copy Markdown

Problem

The build fails on toolchains with GCC 15+ (e.g. Ubuntu 24.10+/25.04+/26.04) due to
-Wunterminated-string-initialization, a new warning in GCC 15 that's part of -Wall
and gets promoted to a hard error by this project's -Werror.

Three fixed-size char arrays are initialized with string literals sized to fit the
visible characters but not the NUL terminator GCC also wants space for:

  • interactive.c: spinner[4] = "|/-\\" (4 visible chars, needs 5)
  • uat2esnt/uat_decode.c: base40_alphabet[40] = "0123... .." (40 visible chars, needs 41)
  • ais_charset.c / ais_charset.h: ais_charset[64] = "@ABC...>?" (64 visible chars, needs 65)

Fix

Grow each array by one byte to hold the terminator. I checked every read site for all
three arrays before changing sizes:

  • spinner is indexed via % 4 in interactive.c — unaffected by growing to 5.
  • base40_alphabet is indexed via % 40 in uat_decode.c — unaffected by growing to 41.
  • ais_charset is indexed by 6-bit bitfields (0–63) across comm_b.c, mode_s.c, and
    net_io.c — unaffected by growing to 65.

No behavior changes; this is purely a build-compatibility fix. I found all three
instances by scanning the source tree for char arr[N] = "literal" where the literal's
length + 1 exceeds N, so this should be the complete set of build breaks from this
warning.

Testing

Built clean on Ubuntu 26.04 (aarch64, GCC 15) where it previously failed at each of
these three spots in sequence. Also confirmed no other instances of this pattern exist
in the tree.

Alvaro Prieto added 3 commits August 1, 2026 09:49
char spinner[4] = "|/-\\" truncates the NUL terminator, which newer
GCC (13+) flags as -Werror=unterminated-string-initialization,
breaking the build on distros with modern toolchains (e.g. Ubuntu
24.04+). Array only needs to grow to 5; the read loop already indexes
with % 4 so behavior is unchanged.
Same class of bug as the previous commit: ais_charset[64] and
base40_alphabet[40] are each one byte too small to hold their string
literal's NUL terminator. GCC 15's -Wunterminated-string-initialization
(part of -Wall) flags these as errors under -Werror. All access sites
use bounded bit-field indices (0-63 and mod-40 respectively), so
growing the arrays by one byte is behavior-neutral.
Missed in the previous commit: ais_charset.h declares extern char
ais_charset[64], which now conflicts with the [65] definition in
ais_charset.c.
@alvarop alvarop changed the title Fix spinner array too small for string literal Fix build failure on GCC 15+: string literals truncating array NUL terminators Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant