From 64f0f5028bc6e8eba07071f8d182bb0d54f027fb Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 18 Jan 2025 18:14:56 +0100 Subject: [PATCH] [LoRaWAN] Cppcheck fixes --- src/protocols/LoRaWAN/LoRaWAN.cpp | 3 ++- src/utils/Cryptography.cpp | 4 ++-- src/utils/Cryptography.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/protocols/LoRaWAN/LoRaWAN.cpp b/src/protocols/LoRaWAN/LoRaWAN.cpp index 948fffe7c..7c1323711 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.cpp +++ b/src/protocols/LoRaWAN/LoRaWAN.cpp @@ -2417,7 +2417,8 @@ void LoRaWANNode::postprocessMacLinkAdr(uint8_t* ack, uint8_t cLen) { int16_t LoRaWANNode::getMacCommand(uint8_t cid, LoRaWANMacCommand_t* cmd) { for(size_t i = 0; i < RADIOLIB_LORAWAN_NUM_MAC_COMMANDS; i++) { if(MacTable[i].cid == cid) { - memcpy(reinterpret_cast(cmd), (void*)&MacTable[i], sizeof(LoRaWANMacCommand_t)); + LoRaWANMacCommand_t* cmdPtr = const_cast(&MacTable[i]); + memcpy(reinterpret_cast(cmd), reinterpret_cast(cmdPtr), sizeof(LoRaWANMacCommand_t)); return(RADIOLIB_ERR_NONE); } } diff --git a/src/utils/Cryptography.cpp b/src/utils/Cryptography.cpp index 43477358e..2039d214b 100644 --- a/src/utils/Cryptography.cpp +++ b/src/utils/Cryptography.cpp @@ -82,7 +82,7 @@ void RadioLibAES128::generateCMAC(const uint8_t* in, size_t len, uint8_t* cmac) delete[] buff; } -bool RadioLibAES128::verifyCMAC(uint8_t* in, size_t len, const uint8_t* cmac) { +bool RadioLibAES128::verifyCMAC(const uint8_t* in, size_t len, const uint8_t* cmac) { uint8_t cmacReal[RADIOLIB_AES128_BLOCK_SIZE]; this->generateCMAC(in, len, cmacReal); for(size_t i = 0; i < RADIOLIB_AES128_BLOCK_SIZE; i++) { @@ -192,7 +192,7 @@ void RadioLibAES128::blockLeftshift(uint8_t* dst, const uint8_t* src) { } void RadioLibAES128::generateSubkeys(uint8_t* key1, uint8_t* key2) { - uint8_t const_Zero[] = { + const uint8_t const_Zero[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/utils/Cryptography.h b/src/utils/Cryptography.h index da5bb33f9..4a5ddca52 100644 --- a/src/utils/Cryptography.h +++ b/src/utils/Cryptography.h @@ -142,7 +142,7 @@ class RadioLibAES128 { \param cmac CMAC to verify. \returns True if valid, false otherwise. */ - bool verifyCMAC(uint8_t* in, size_t len, const uint8_t* cmac); + bool verifyCMAC(const uint8_t* in, size_t len, const uint8_t* cmac); private: uint8_t* keyPtr = nullptr;