Bug #5764
openGCC does not check format strings in LOGPFSM macros
0%
Description
Recently I submitted a patch with an error in one of the LOGPFSM statements ('%s' instead of '%d' for printing an uint16_t):
https://gerrit.osmocom.org/c/osmocom-bb/+/30054/1
https://gerrit.osmocom.org/c/osmocom-bb/+/30054/1/src/host/trxcon/src/trxcon_fsm.c#229
Surprisingly, gcc does not emit any warnings and compiles obviously wrong code just fine. This is not specific to osmocom-bb.git
, I was able to reproduce this problem in other Osmocom repositories, except libosmocore.git
where it magically does emit -Wformat
warnings as expected. This is most likely a bug in gcc, because clang behaves as expected.
I also tried to narrow down the problem to a specific macro:
#define FMT "Test %s\n"
#define ARG 1337, "extra", -1
/* GCC does emit -Wformat / -Wformat-extra-args warnings as expected */
LOGP(DAPP, LOGL_ERROR, FMT, ARG);
/* GCC does *not* emit any warnings, clang does */
LOGPFSML(fi, LOGL_ERROR, FMT, ARG);
LOGPFSMLSRC(fi, LOGL_ERROR, __FILE__, __LINE__, FMT, ARG);
LOGPFSMSLSRC(fi, (fi) ? (fi)->fsm->log_subsys : DLGLOBAL, LOGL_ERROR,
__FILE__, __LINE__, FMT, ARG);
/* GCC does emit -Wformat / -Wformat-extra-args warnings as expected */
LOGPSRC((fi)->fsm->log_subsys, LOGL_ERROR,
__FILE__, __LINE__,
"%s{%s}: " FMT,
osmo_fsm_inst_name(fi),
(fi) ? osmo_fsm_state_name((fi)->fsm, (fi)->state) : "fi=NULL", ARG);
Running gcc with -E -P
confirms that the preprocessor expands all LOGPFSM
statements identical to the last LOGPSRC
.
No data to display