trezor-firmware icon indicating copy to clipboard operation
trezor-firmware copied to clipboard

Conform to -Wstrict-prototypes on New Compilers

Open invd opened this issue 3 years ago • 1 comments

The codebase contains a number of C functions that do not take any parameters but are not marked with void. This style is deprecated, and compilers warn for it with -Wstrict-prototypes:

zkp_context.c:54:21: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
int zkp_context_init() {
                    ^
                     void

With the upcoming clang-15 compiler, -Wstrict-prototypes is now enabled by default, leading to build failures due to treating warnings as errors via -Werror. The relevant change discussion also gives some context why the explicit void definition is better.

I propose switching all zero-parameter functions to the explicit void definition, and explicitly enabling -Wstrict-prototypes on gcc builds as well to ensure that no regressions are introduced. There are about a dozen cases in zkp_context.c, oled.c, common.c, config.c, fsm_msg_common.h, stellar.c and other places.

This may help the compiler to produce better code but should otherwise introduce no functional changes.

invd avatar Jul 01 '22 12:07 invd

Update: -Wstrict-prototypes is already explicitly enabled in the legacy and crypto build configurations. It appears that the warning behavior has changed with clang-15, though.

invd avatar Jul 01 '22 14:07 invd