From 817efbbccc4137dedcf71195c0a49b278a93dd83 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Fri, 4 Oct 2024 19:45:52 +0100 Subject: [PATCH] txCommands.c: warning: variable ... is used uninitialized whenever Maybe ASSERT are not always active, so defensive coding solution. txCommands.c:883:6: warning: variable 'but' is used uninitialized whenever switch default is taken txCommands.c:888:6: warning: variable 'act' is used uninitialized whenever switch default is taken clang18 -Wall warning cleanup [-Wsometimes-uninitialized] --- textio/txCommands.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/textio/txCommands.c b/textio/txCommands.c index 32b1c5ee..dbf82652 100644 --- a/textio/txCommands.c +++ b/textio/txCommands.c @@ -880,15 +880,16 @@ txLogCommand(cmd) case TX_LEFT_BUTTON: { but = 0; break; }; case TX_MIDDLE_BUTTON: { but = 1; break; }; case TX_RIGHT_BUTTON: { but = 2; break; }; - default: {ASSERT(FALSE, "txLogCommand"); break; }; + default: {ASSERT(FALSE, "txLogCommand"); but = -1; break; }; } switch(cmd->tx_buttonAction) { case TX_BUTTON_DOWN: { act = 0; break; }; case TX_BUTTON_UP: { act = 1; break; }; - default: {ASSERT(FALSE, "txLogCommand"); break; }; + default: {ASSERT(FALSE, "txLogCommand"); act = -1; break; }; } - fprintf(txLogFile, "%spushbutton %s %s\n", + if (but >= 0 && act >= 0) + fprintf(txLogFile, "%spushbutton %s %s\n", pfix, txButTable[but], txActTable[act]); } if (txLogFlags & TX_LOG_UPDATE)