diff --git a/CMakeLists.txt b/CMakeLists.txt index f4500181d..5c2d02c2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,8 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang") endif() set(OT_CFLAGS - $<$:${OT_CFLAGS} -Wall -Wextra -Wshadow> - $<$:${OT_CFLAGS} -Wall -Wextra -Wshadow -Wno-c++14-compat -fno-exceptions> + $<$:${OT_CFLAGS} -Wall -Wformat-nonliteral -Wextra -Wshadow> + $<$:${OT_CFLAGS} -Wall -Wformat-nonliteral -Wextra -Wshadow -Wno-c++14-compat -fno-exceptions> $<$:-Wc99-extensions> ) endif() diff --git a/examples/apps/cli/cli_uart.cpp b/examples/apps/cli/cli_uart.cpp index cee0903ab..c3ca42698 100644 --- a/examples/apps/cli/cli_uart.cpp +++ b/examples/apps/cli/cli_uart.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "cli/cli_config.h" #include "common/code_utils.hpp" @@ -221,7 +222,7 @@ static void Send(void) { #if OPENTHREAD_CONFIG_ENABLE_DEBUG_UART /* duplicate the output to the debug uart */ - otSysDebugUart_write_bytes(reinterpret_cast(sTxBuffer + sTxHead), sSendLength); + otPlatDebugUart_write_bytes(reinterpret_cast(sTxBuffer + sTxHead), sSendLength); #endif IgnoreError(otPlatUartSend(reinterpret_cast(sTxBuffer + sTxHead), sSendLength)); } diff --git a/examples/platforms/utils/CMakeLists.txt b/examples/platforms/utils/CMakeLists.txt index 3e4a680d0..d4d26ba58 100644 --- a/examples/platforms/utils/CMakeLists.txt +++ b/examples/platforms/utils/CMakeLists.txt @@ -47,6 +47,10 @@ if(OT_RTT_UART) ) endif() +target_compile_options(openthread-platform-utils PRIVATE + ${OT_CFLAGS} +) + target_include_directories(openthread-platform-utils PRIVATE ${OT_PUBLIC_INCLUDES} $ diff --git a/examples/platforms/utils/logging_rtt.h b/examples/platforms/utils/logging_rtt.h index 98d006bfa..2e513e8c8 100644 --- a/examples/platforms/utils/logging_rtt.h +++ b/examples/platforms/utils/logging_rtt.h @@ -124,7 +124,8 @@ void utilsLogRttDeinit(void); * @param[in] aFormat A pointer to the format string. * @param[in] ap va_list matching information for aFormat */ -void utilsLogRttOutput(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list ap); +void utilsLogRttOutput(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list ap) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(3, 0); #ifdef __cplusplus } // extern "C" diff --git a/examples/platforms/utils/mac_frame.cpp b/examples/platforms/utils/mac_frame.cpp index 88c144001..0152da40a 100644 --- a/examples/platforms/utils/mac_frame.cpp +++ b/examples/platforms/utils/mac_frame.cpp @@ -383,6 +383,7 @@ void otMacFrameUpdateTimeIe(otRadioFrame *aFrame, uint64_t aRadioTime, otRadioCo uint8_t *timeIe; uint64_t time; + OT_UNUSED_VARIABLE(aRadioContext); VerifyOrExit((aFrame->mInfo.mTxInfo.mIeInfo != nullptr) && (aFrame->mInfo.mTxInfo.mIeInfo->mTimeIeOffset != 0)); timeIe = aFrame->mPsdu + aFrame->mInfo.mTxInfo.mIeInfo->mTimeIeOffset; @@ -434,7 +435,6 @@ bool otMacFrameSrcAddrMatchCslReceiverPeer(const otRadioFrame *aFrame, const otR break; case Mac::Address::kTypeExtended: - VerifyOrExit(*reinterpret_cast(aRadioContext->mCslExtAddress.m8) != 0); VerifyOrExit(src.GetExtended() == *static_cast(&aRadioContext->mCslExtAddress)); matches = true; break; diff --git a/examples/platforms/utils/otns_utils.cpp b/examples/platforms/utils/otns_utils.cpp index 1c8db69c9..e432a6355 100644 --- a/examples/platforms/utils/otns_utils.cpp +++ b/examples/platforms/utils/otns_utils.cpp @@ -43,6 +43,10 @@ using namespace ot; #if OPENTHREAD_CONFIG_OTNS_ENABLE OT_TOOL_WEAK -void otPlatOtnsStatus(const char *aStatus) { LogAlways("[OTNS] %s", aStatus); } +void otPlatOtnsStatus(const char *aStatus) +{ + OT_UNUSED_VARIABLE(aStatus); + LogAlways("[OTNS] %s", aStatus); +} #endif // OPENTHREAD_CONFIG_OTNS_ENABLE diff --git a/include/openthread/cli.h b/include/openthread/cli.h index bd0941244..df7cdc8dd 100644 --- a/include/openthread/cli.h +++ b/include/openthread/cli.h @@ -76,7 +76,8 @@ typedef struct otCliCommand * * @returns Number of bytes written by the callback. */ -typedef int (*otCliOutputCallback)(void *aContext, const char *aFormat, va_list aArguments); +typedef int (*otCliOutputCallback)(void *aContext, const char *aFormat, va_list aArguments) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); /** * Initialize the CLI module. diff --git a/include/openthread/instance.h b/include/openthread/instance.h index afa1eb70a..4aeee1947 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (566) +#define OPENTHREAD_API_VERSION (567) /** * @addtogroup api-instance diff --git a/include/openthread/ncp.h b/include/openthread/ncp.h index ea6c3b373..b8969db4b 100644 --- a/include/openthread/ncp.h +++ b/include/openthread/ncp.h @@ -42,6 +42,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -135,7 +136,8 @@ otError otNcpStreamWrite(int aStreamId, const uint8_t *aDataPtr, int aDataLen); * @param[in] aFormat A pointer to the format string. * @param[in] aArgs va_list matching aFormat. */ -void otNcpPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs); +void otNcpPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(3, 0); //----------------------------------------------------------------------------------------- // Peek/Poke memory access control delegates diff --git a/include/openthread/platform/debug_uart.h b/include/openthread/platform/debug_uart.h index b58753e4b..ef9b66997 100644 --- a/include/openthread/platform/debug_uart.h +++ b/include/openthread/platform/debug_uart.h @@ -33,6 +33,7 @@ #include #include +#include /** * @file @@ -82,7 +83,7 @@ extern "C" { * * This is a WEAK symbol that can easily be overridden as needed. */ -void otPlatDebugUart_printf(const char *fmt, ...); +void otPlatDebugUart_printf(const char *fmt, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); /** * Standard vprintf() to the debug uart, with no log decoration. @@ -100,7 +101,7 @@ void otPlatDebugUart_printf(const char *fmt, ...); * symbol because the platform provides a UART_vprintf() like * function that can handle an arbitrary length output. */ -void otPlatDebugUart_vprintf(const char *fmt, va_list ap); +void otPlatDebugUart_vprintf(const char *fmt, va_list ap) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 0); /** * Platform specific write single byte to Debug Uart diff --git a/include/openthread/platform/diag.h b/include/openthread/platform/diag.h index 9c75c9015..6a37fd4a3 100644 --- a/include/openthread/platform/diag.h +++ b/include/openthread/platform/diag.h @@ -42,6 +42,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -72,7 +73,8 @@ typedef enum * @param[in] aArguments The format string arguments. * @param[out] aContext A pointer to the user context. */ -typedef void (*otPlatDiagOutputCallback)(const char *aFormat, va_list aArguments, void *aContext); +typedef void (*otPlatDiagOutputCallback)(const char *aFormat, va_list aArguments, void *aContext) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 0); /** * Sets the platform diag output callback. diff --git a/include/openthread/platform/logging.h b/include/openthread/platform/logging.h index 4c1f3f58d..6b587b725 100644 --- a/include/openthread/platform/logging.h +++ b/include/openthread/platform/logging.h @@ -35,6 +35,8 @@ #ifndef OPENTHREAD_PLATFORM_LOGGING_H_ #define OPENTHREAD_PLATFORM_LOGGING_H_ +#include + #ifdef __cplusplus extern "C" { #endif @@ -146,7 +148,8 @@ typedef enum otLogRegion * @param[in] aFormat A pointer to the format string. * @param[in] ... Arguments for the format specification. */ -void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...); +void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(3, 4); /** * Handles OpenThread log level changes. diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 58c4ae8d0..981baad8c 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -324,8 +324,9 @@ private: #endif // OPENTHREAD_FTD || OPENTHREAD_MTD #if OPENTHREAD_CONFIG_DIAG_ENABLE - static void HandleDiagOutput(const char *aFormat, va_list aArguments, void *aContext); - void HandleDiagOutput(const char *aFormat, va_list aArguments); + static void HandleDiagOutput(const char *aFormat, va_list aArguments, void *aContext) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 0); + void HandleDiagOutput(const char *aFormat, va_list aArguments) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); #endif void SetCommandTimeout(uint32_t aTimeoutMilli); diff --git a/src/cli/cli_utils.hpp b/src/cli/cli_utils.hpp index 8ebbc86b0..a32163f26 100644 --- a/src/cli/cli_utils.hpp +++ b/src/cli/cli_utils.hpp @@ -553,7 +553,10 @@ public: otError error = OT_ERROR_NONE; VerifyOrExit(aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" OutputLine(FormatStringFor(), aGetHandler(GetInstancePtr())); +#pragma GCC diagnostic pop exit: return error; @@ -755,14 +758,10 @@ template <> inline constexpr const char *Utils::FormatStringFor(void) { template <> inline constexpr const char *Utils::FormatStringFor(void) { return "%u"; } -template <> inline constexpr const char *Utils::FormatStringFor(void) { return "%lu"; } - template <> inline constexpr const char *Utils::FormatStringFor(void) { return "%d"; } template <> inline constexpr const char *Utils::FormatStringFor(void) { return "%d"; } -template <> inline constexpr const char *Utils::FormatStringFor(void) { return "%ld"; } - template <> inline constexpr const char *Utils::FormatStringFor(void) { return "%s"; } // Specialization of ProcessGet<> for `uint32_t` and `int32_t` @@ -772,7 +771,8 @@ template <> inline otError Utils::ProcessGet(Arg aArgs[], GetHandler(), ToUlong(aGetHandler(GetInstancePtr()))); + static_assert(sizeof(unsigned long) >= sizeof(uint32_t), "OpenThread assumes unsigned long is at least 32bit"); + OutputLine("%lu", ToUlong(aGetHandler(GetInstancePtr()))); exit: return error; @@ -783,7 +783,8 @@ template <> inline otError Utils::ProcessGet(Arg aArgs[], GetHandler(), static_cast(aGetHandler(GetInstancePtr()))); + static_assert(sizeof(long) >= sizeof(int32_t), "OpenThread assumes long is at least 32bit"); + OutputLine("%ld", static_cast(aGetHandler(GetInstancePtr()))); exit: return error; diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 4d45a21a3..bd8b04b98 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -661,13 +661,15 @@ protected: static unsigned int ConvertLogRegion(otLogRegion aLogRegion); #if OPENTHREAD_CONFIG_DIAG_ENABLE - static void HandleDiagOutput_Jump(const char *aFormat, va_list aArguments, void *aContext); - void HandleDiagOutput(const char *aFormat, va_list aArguments); + static void HandleDiagOutput_Jump(const char *aFormat, va_list aArguments, void *aContext) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 0); + void HandleDiagOutput(const char *aFormat, va_list aArguments) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); #endif #if OPENTHREAD_CONFIG_NCP_CLI_STREAM_ENABLE - static int HandleCliOutput(void *aContext, const char *aFormat, va_list aArguments); - int HandleCliOutput(const char *aFormat, va_list aArguments); + static int HandleCliOutput(void *aContext, const char *aFormat, va_list aArguments) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); + int HandleCliOutput(const char *aFormat, va_list aArguments) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); #endif #if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK diff --git a/src/posix/cli_readline.cpp b/src/posix/cli_readline.cpp index 3a402cbef..f18ea0083 100644 --- a/src/posix/cli_readline.cpp +++ b/src/posix/cli_readline.cpp @@ -73,6 +73,9 @@ static void InputCallback(char *aLine) } } +static int OutputCallback(void *aContext, const char *aFormat, va_list aArguments) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); + static int OutputCallback(void *aContext, const char *aFormat, va_list aArguments) { OT_UNUSED_VARIABLE(aContext); diff --git a/src/posix/cli_stdio.cpp b/src/posix/cli_stdio.cpp index 54a194c4b..bcb1b0771 100644 --- a/src/posix/cli_stdio.cpp +++ b/src/posix/cli_stdio.cpp @@ -50,6 +50,8 @@ namespace { +int OutputCallback(void *aContext, const char *aFormat, va_list aArguments) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); + int OutputCallback(void *aContext, const char *aFormat, va_list aArguments) { OT_UNUSED_VARIABLE(aContext); diff --git a/src/posix/platform/daemon.cpp b/src/posix/platform/daemon.cpp index c42f7cdcb..b1645e080 100644 --- a/src/posix/platform/daemon.cpp +++ b/src/posix/platform/daemon.cpp @@ -32,9 +32,7 @@ #include #endif #include -#include #include -#include #include #include #include @@ -62,20 +60,17 @@ namespace { typedef char(Filename)[sizeof(sockaddr_un::sun_path)]; -void GetFilename(Filename &aFilename, const char *aPattern) -{ - int rval; - const char *netIfName = strlen(gNetifName) > 0 ? gNetifName : OPENTHREAD_POSIX_CONFIG_THREAD_NETIF_DEFAULT_NAME; - - rval = snprintf(aFilename, sizeof(aFilename), aPattern, netIfName); - if (rval < 0 && static_cast(rval) >= sizeof(aFilename)) - { - DieNow(OT_EXIT_INVALID_ARGUMENTS); - } -} - } // namespace +// using macro to avoid the warning about format-nonliteral +#define GetFilename(aFilename, aPattern) \ + do \ + { \ + int rval = snprintf(aFilename, sizeof(aFilename), aPattern, \ + (gNetifName[0] ? gNetifName : OPENTHREAD_POSIX_CONFIG_THREAD_NETIF_DEFAULT_NAME)); \ + VerifyOrDie(rval > 0 && static_cast(rval) < sizeof(aFilename), OT_EXIT_INVALID_ARGUMENTS); \ + } while (0) + const char Daemon::kLogModuleName[] = "Daemon"; int Daemon::OutputFormat(const char *aFormat, ...) diff --git a/src/posix/platform/daemon.hpp b/src/posix/platform/daemon.hpp index c4ced601b..423f2b904 100644 --- a/src/posix/platform/daemon.hpp +++ b/src/posix/platform/daemon.hpp @@ -30,6 +30,10 @@ #include "openthread-posix-config.h" +#include + +#include + #include "core/common/non_copyable.hpp" #include "logger.hpp" @@ -49,10 +53,10 @@ public: void TearDown(void); void Update(Mainloop::Context &aContext) override; void Process(const Mainloop::Context &aContext) override; - int OutputFormatV(const char *aFormat, va_list aArguments); + int OutputFormatV(const char *aFormat, va_list aArguments) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); private: - int OutputFormat(const char *aFormat, ...); + int OutputFormat(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 3); void createListenSocketOrDie(void); void InitializeSessionSocket(void); diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index 40547e2cd..8ac42caee 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -296,6 +296,12 @@ static bool sIsSyncingState = false; static const char kLogModuleName[] = "Netif"; +static void LogCrit(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); +static void LogWarn(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); +static void LogNote(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); +static void LogInfo(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); +static void LogDebg(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); + static void LogCrit(const char *aFormat, ...) { va_list args; diff --git a/src/posix/platform/radio.cpp b/src/posix/platform/radio.cpp index 82f710c0c..4a525e7d1 100644 --- a/src/posix/platform/radio.cpp +++ b/src/posix/platform/radio.cpp @@ -40,6 +40,7 @@ #include "common/code_utils.hpp" #include "common/new.hpp" +#include "common/string.hpp" #include "posix/platform/radio.hpp" #include "posix/platform/spinel_driver_getter.hpp" #include "posix/platform/spinel_manager.hpp" @@ -568,6 +569,9 @@ static void *sDiagCallbackContext = nullptr; static char *sDiagOutput = nullptr; static uint16_t sDiagOutputLen = 0; +static void handleDiagOutput(const char *aFormat, va_list aArguments, void *aContext) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 0); + static void handleDiagOutput(const char *aFormat, va_list aArguments, void *aContext) { OT_UNUSED_VARIABLE(aContext); @@ -763,15 +767,15 @@ otError otPlatDiagRadioGetPowerSettings(otInstance *aInstance, { OT_UNUSED_VARIABLE(aInstance); static constexpr uint16_t kRawPowerStringSize = OPENTHREAD_CONFIG_POWER_CALIBRATION_RAW_POWER_SETTING_SIZE * 2 + 1; - static constexpr uint16_t kFmtStringSize = 100; otError error; char cmd[OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE]; char output[OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE]; int targetPower; int actualPower; - char rawPowerSetting[kRawPowerStringSize]; - char fmt[kFmtStringSize]; + char rawPowerSetting[OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE]; + + static_assert(OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE >= kRawPowerStringSize, "RawPowerSetting too large"); assert((aTargetPower != nullptr) && (aActualPower != nullptr) && (aRawPowerSetting != nullptr) && (aRawPowerSettingLength != nullptr)); @@ -780,9 +784,10 @@ otError otPlatDiagRadioGetPowerSettings(otInstance *aInstance, snprintf(cmd, sizeof(cmd), "powersettings %d", aChannel); SuccessOrExit(error = GetRadioSpinel().PlatDiagProcess(cmd)); - snprintf(fmt, sizeof(fmt), "TargetPower(0.01dBm): %%d\r\nActualPower(0.01dBm): %%d\r\nRawPowerSetting: %%%us\r\n", - kRawPowerStringSize); - VerifyOrExit(sscanf(output, fmt, &targetPower, &actualPower, rawPowerSetting) == 3, error = OT_ERROR_FAILED); + output[sizeof(output) - 1] = ot::kNullChar; + VerifyOrExit(sscanf(output, "TargetPower(0.01dBm): %d\r\nActualPower(0.01dBm): %d\r\nRawPowerSetting: %s\r\n", + &targetPower, &actualPower, rawPowerSetting) == 3, + error = OT_ERROR_FAILED); SuccessOrExit( error = ot::Utils::CmdLineParser::ParseAsHexString(rawPowerSetting, *aRawPowerSettingLength, aRawPowerSetting)); *aTargetPower = static_cast(targetPower); diff --git a/src/posix/platform/rcp_caps_diag.hpp b/src/posix/platform/rcp_caps_diag.hpp index d1c217bb6..da1d50770 100644 --- a/src/posix/platform/rcp_caps_diag.hpp +++ b/src/posix/platform/rcp_caps_diag.hpp @@ -126,13 +126,14 @@ private: void OutputExtendedSrcMatchTableSize(void); void OutputShortSrcMatchTableSize(void); - static void HandleDiagOutput(const char *aFormat, va_list aArguments, void *aContext); - void HandleDiagOutput(const char *aFormat, va_list aArguments); + static void HandleDiagOutput(const char *aFormat, va_list aArguments, void *aContext) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 0); + void HandleDiagOutput(const char *aFormat, va_list aArguments) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); void OutputFormat(const char *aName, const char *aValue); void OutputFormat(const char *aName, uint32_t aValue); void OutputResult(const SpinelEntry &aEntry, otError error); - void Output(const char *aFormat, ...); + void Output(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 3); static const char *SupportToString(bool aSupport); static const char *RadioCapbilityToString(uint32_t aCapability); diff --git a/src/posix/platform/system.cpp b/src/posix/platform/system.cpp index 9dfc22d1b..42017045f 100644 --- a/src/posix/platform/system.cpp +++ b/src/posix/platform/system.cpp @@ -497,13 +497,14 @@ void otSysMainloopProcess(otInstance *aInstance, const otSysMainloopContext *aMa bool IsSystemDryRun(void) { return gDryRun; } #if OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE && OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE -void otSysCliInitUsingDaemon(otInstance *aInstance) +namespace { +int OutputCallback(void *aContext, const char *aFormat, va_list aArguments) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); + +int OutputCallback(void *aContext, const char *aFormat, va_list aArguments) { - otCliInit( - aInstance, - [](void *aContext, const char *aFormat, va_list aArguments) -> int { - return static_cast(aContext)->OutputFormatV(aFormat, aArguments); - }, - &ot::Posix::Daemon::Get()); + return static_cast(aContext)->OutputFormatV(aFormat, aArguments); } +} // namespace + +void otSysCliInitUsingDaemon(otInstance *aInstance) { otCliInit(aInstance, OutputCallback, &ot::Posix::Daemon::Get()); } #endif diff --git a/src/posix/platform/trel.cpp b/src/posix/platform/trel.cpp index 690afa267..57b0da736 100644 --- a/src/posix/platform/trel.cpp +++ b/src/posix/platform/trel.cpp @@ -79,6 +79,12 @@ static int sSocket = -1; static const char kLogModuleName[] = "Trel"; +static void LogCrit(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); +static void LogWarn(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); +static void LogNote(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); +static void LogInfo(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); +static void LogDebg(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); + static void LogCrit(const char *aFormat, ...) { va_list args; diff --git a/src/posix/platform/utils.hpp b/src/posix/platform/utils.hpp index 41f64e234..41970770b 100644 --- a/src/posix/platform/utils.hpp +++ b/src/posix/platform/utils.hpp @@ -67,7 +67,7 @@ int SocketWithCloseExec(int aDomain, int aType, int aProtocol, SocketBlockOption * @retval OT_ERROR_NONE The command was executed successfully. * @retval OT_ERROR_FAILED It failed to execute the command. */ -otError ExecuteCommand(const char *aFormat, ...); +otError ExecuteCommand(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); } // namespace Posix } // namespace ot