From 1c17e31589532f453ef3c1f5cbe98b122bb2fc52 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 27 Sep 2022 09:27:27 +0200 Subject: [PATCH] Fix printf format warnings These warnings are caused because frequencies are stored as `uint32_t`, which is `unsigned long`, while the printf format expects `int`. In practice, this does not actually cause problems, since on STM32 gcc `long` and `int` are both 32-bits and frequencies are never large enough to cause signed vs unsigned ambiguity. Since printf has no format specifiers for e.g. uint32_t (libc does have some macros for this, but those really hurt readability), this is tricky to fix in a portable way (other architectures or compilers might have `uint32_t` equal to `unsigned int` instead of `unsigned long`), this fix just casts the frequency to `unsigned` before passing it to printf (and for good measure, also convert the specifier from `%d` to `%u`). This does mean this printing will break if `int` is not at least 32-bits (e.g. on AVR), but given the scope of this library, that should be acceptable. --- Middlewares/Third_Party/LoRaWAN/Mac/Region/RegionCommon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Middlewares/Third_Party/LoRaWAN/Mac/Region/RegionCommon.c b/Middlewares/Third_Party/LoRaWAN/Mac/Region/RegionCommon.c index 2723e09f..ab90eac9 100644 --- a/Middlewares/Third_Party/LoRaWAN/Mac/Region/RegionCommon.c +++ b/Middlewares/Third_Party/LoRaWAN/Mac/Region/RegionCommon.c @@ -562,7 +562,7 @@ void RegionCommonRxBeaconSetup( RegionCommonRxBeaconSetupParams_t* rxBeaconSetup 1, 0, 10, rxBeaconSetupParams->SymbolTimeout, true, rxBeaconSetupParams->BeaconSize, false, 0, 0, false, rxContinuous ); Radio.Rx( rxBeaconSetupParams->RxTime ); - MW_LOG(TS_ON, VLEVEL_M, "RX_BC on freq %d Hz at DR %d\r\n", rxBeaconSetupParams->Frequency, rxBeaconSetupParams->BeaconDatarate ); + MW_LOG(TS_ON, VLEVEL_M, "RX_BC on freq %u Hz at DR %d\r\n", (unsigned)rxBeaconSetupParams->Frequency, rxBeaconSetupParams->BeaconDatarate ); } void RegionCommonCountNbOfEnabledChannels( RegionCommonCountNbOfEnabledChannelsParams_t* countNbOfEnabledChannelsParams, @@ -696,15 +696,15 @@ void RegionCommonRxConfigPrint(LoRaMacRxSlot_t rxSlot, uint32_t frequency, int8_ { if ( rxSlot < RX_SLOT_NONE ) { - MW_LOG(TS_ON, VLEVEL_M, "RX_%s on freq %d Hz at DR %d\r\n", EventRXSlotStrings[rxSlot], frequency, dr ); + MW_LOG(TS_ON, VLEVEL_M, "RX_%s on freq %u Hz at DR %d\r\n", EventRXSlotStrings[rxSlot], (unsigned)frequency, dr ); } else { - MW_LOG(TS_ON, VLEVEL_M, "RX on freq %d Hz at DR %d\r\n", frequency, dr ); + MW_LOG(TS_ON, VLEVEL_M, "RX on freq %u Hz at DR %d\r\n", (unsigned)frequency, dr ); } } void RegionCommonTxConfigPrint(uint32_t frequency, int8_t dr) { - MW_LOG(TS_ON, VLEVEL_M, "TX on freq %d Hz at DR %d\r\n", frequency, dr ); + MW_LOG(TS_ON, VLEVEL_M, "TX on freq %u Hz at DR %d\r\n", (unsigned)frequency, dr ); }