From 1b88b045d0700c7afa05aa91a8518237d10039b0 Mon Sep 17 00:00:00 2001 From: andrei-menzopol <96489227+andrei-menzopol@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:29:52 +0200 Subject: [PATCH] [logging] fix format strings (#8446) This commit fixes the format string in logging functions. When openthread is included in other projects that use the -Werror option in their builds, such as Matter, these format string errors appear. In this case, it can be seen in radio.h that the structure members are uint32_t but printed with %u. The size of types depends on the target, there needs to be a casing. --- src/cli/cli.cpp | 4 ++-- src/lib/spinel/radio_spinel_impl.hpp | 34 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 44e2b738e..130f347cf 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2413,12 +2413,12 @@ template <> otError Interpreter::Process(Arg aArgs[]) SuccessOrExit(error = otPlatRadioGetCoexMetrics(GetInstancePtr(), &metrics)); OutputLine("Stopped: %s", metrics.mStopped ? "true" : "false"); - OutputLine("Grant Glitch: %u", metrics.mNumGrantGlitch); + OutputLine("Grant Glitch: %lu", ToUlong(metrics.mNumGrantGlitch)); OutputLine("Transmit metrics"); for (const RadioCoexMetricName &metric : kTxMetricNames) { - OutputLine(kIndentSize, "%s: %u", metric.mName, metrics.*metric.mValuePtr); + OutputLine(kIndentSize, "%s: %lu", metric.mName, ToUlong(metrics.*metric.mValuePtr)); } OutputLine("Receive metrics"); diff --git a/src/lib/spinel/radio_spinel_impl.hpp b/src/lib/spinel/radio_spinel_impl.hpp index 6ab6d3c54..4b51c7e81 100644 --- a/src/lib/spinel/radio_spinel_impl.hpp +++ b/src/lib/spinel/radio_spinel_impl.hpp @@ -3032,23 +3032,23 @@ void RadioSpinel::LogSpinelFrame(const uint8_ VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE); otLogDebgPlat("%s ...", buf); - otLogDebgPlat(" txRequest:%u", metrics.mNumTxRequest); - otLogDebgPlat(" txGrantImmediate:%u", metrics.mNumTxGrantImmediate); - otLogDebgPlat(" txGrantWait:%u", metrics.mNumTxGrantWait); - otLogDebgPlat(" txGrantWaitActivated:%u", metrics.mNumTxGrantWaitActivated); - otLogDebgPlat(" txGrantWaitTimeout:%u", metrics.mNumTxGrantWaitTimeout); - otLogDebgPlat(" txGrantDeactivatedDuringRequest:%u", metrics.mNumTxGrantDeactivatedDuringRequest); - otLogDebgPlat(" txDelayedGrant:%u", metrics.mNumTxDelayedGrant); - otLogDebgPlat(" avgTxRequestToGrantTime:%u", metrics.mAvgTxRequestToGrantTime); - otLogDebgPlat(" rxRequest:%u", metrics.mNumRxRequest); - otLogDebgPlat(" rxGrantImmediate:%u", metrics.mNumRxGrantImmediate); - otLogDebgPlat(" rxGrantWait:%u", metrics.mNumRxGrantWait); - otLogDebgPlat(" rxGrantWaitActivated:%u", metrics.mNumRxGrantWaitActivated); - otLogDebgPlat(" rxGrantWaitTimeout:%u", metrics.mNumRxGrantWaitTimeout); - otLogDebgPlat(" rxGrantDeactivatedDuringRequest:%u", metrics.mNumRxGrantDeactivatedDuringRequest); - otLogDebgPlat(" rxDelayedGrant:%u", metrics.mNumRxDelayedGrant); - otLogDebgPlat(" avgRxRequestToGrantTime:%u", metrics.mAvgRxRequestToGrantTime); - otLogDebgPlat(" rxGrantNone:%u", metrics.mNumRxGrantNone); + otLogDebgPlat(" txRequest:%lu", ToUlong(metrics.mNumTxRequest)); + otLogDebgPlat(" txGrantImmediate:%lu", ToUlong(metrics.mNumTxGrantImmediate)); + otLogDebgPlat(" txGrantWait:%lu", ToUlong(metrics.mNumTxGrantWait)); + otLogDebgPlat(" txGrantWaitActivated:%lu", ToUlong(metrics.mNumTxGrantWaitActivated)); + otLogDebgPlat(" txGrantWaitTimeout:%lu", ToUlong(metrics.mNumTxGrantWaitTimeout)); + otLogDebgPlat(" txGrantDeactivatedDuringRequest:%lu", ToUlong(metrics.mNumTxGrantDeactivatedDuringRequest)); + otLogDebgPlat(" txDelayedGrant:%lu", ToUlong(metrics.mNumTxDelayedGrant)); + otLogDebgPlat(" avgTxRequestToGrantTime:%lu", ToUlong(metrics.mAvgTxRequestToGrantTime)); + otLogDebgPlat(" rxRequest:%lu", ToUlong(metrics.mNumRxRequest)); + otLogDebgPlat(" rxGrantImmediate:%lu", ToUlong(metrics.mNumRxGrantImmediate)); + otLogDebgPlat(" rxGrantWait:%lu", ToUlong(metrics.mNumRxGrantWait)); + otLogDebgPlat(" rxGrantWaitActivated:%lu", ToUlong(metrics.mNumRxGrantWaitActivated)); + otLogDebgPlat(" rxGrantWaitTimeout:%lu", ToUlong(metrics.mNumRxGrantWaitTimeout)); + otLogDebgPlat(" rxGrantDeactivatedDuringRequest:%lu", ToUlong(metrics.mNumRxGrantDeactivatedDuringRequest)); + otLogDebgPlat(" rxDelayedGrant:%lu", ToUlong(metrics.mNumRxDelayedGrant)); + otLogDebgPlat(" avgRxRequestToGrantTime:%lu", ToUlong(metrics.mAvgRxRequestToGrantTime)); + otLogDebgPlat(" rxGrantNone:%lu", ToUlong(metrics.mNumRxGrantNone)); otLogDebgPlat(" stopped:%u", metrics.mStopped); start = buf;