According to the C99 standard, _Bool will only be assigned 0 or 1. However, Nanopb violates strict aliasing rules by using an int_least8_t pointer to write to the underlying memory. This allows the _Bool to contain a value greater than one.
🚨 UNDEFINED BEHAVIOUR ALERT 🚨
Clang heavily relies on this assumption. For example, message.bool_field ? X : Y is often optimized into message.bool_field ^ N, causing bugs in a codebase using Nanopb.
According to the C99 standard,
_Boolwill only be assigned0or1. However, Nanopb violates strict aliasing rules by using anint_least8_tpointer to write to the underlying memory. This allows the_Boolto contain a value greater than one.🚨 UNDEFINED BEHAVIOUR ALERT 🚨
Clang heavily relies on this assumption. For example,
message.bool_field ? X : Yis often optimized intomessage.bool_field ^ N, causing bugs in a codebase using Nanopb.