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