(avr-)gcc 15.x and XXX_init_zero macros

7 views
Skip to first unread message

Wouter Horré

unread,
Sep 30, 2025, 5:55:12 AMSep 30
to nanopb
Hi,

I ran into an issue with the encoding of a proto message with a oneof field that can contain messages of different sizes. I am initializing the message with the XXX_init_zero macro, but somehow the encoded message contained garbage.

After investigation, I found the issue being caused by the avr-gcc upgrade to 15.x. The release notes of GCC 15.x (https://gcc.gnu.org/gcc-15/changes.html) mention:
 
{0} initializer in C or C++ for unions no longer guarantees clearing of the whole union (except for static storage duration initialization), it just initializes the first union member to zero. If initialization of the whole union including padding bits is desirable, use {} (valid in C23 or C++) or use -fzero-init-padding-bits=unions option to restore the old GCC behavior.

I verified that adding -fzero-init-padding-bits=unions solves the issue.

I'm posting here mainly to raise awareness, since I don't think nanopb can fix this (at least not without switching to C23)...

best regards
Wouter

Petteri Aimonen

unread,
Sep 30, 2025, 5:59:22 AMSep 30
to nanopb
Hi,

Thanks for the report.

I'm not sure how much can be done about it, but it would be good to have some kind of warning at least.

--
Petteri
Reply all
Reply to author
Forward
0 new messages