From 814f3db5a27f69c95e39825cc2b3943a9d16428e Mon Sep 17 00:00:00 2001 From: thekurtovic <40248206+thekurtovic@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:56:49 -0500 Subject: [PATCH 1/2] Fix NimBLEUtils::dataToHexString returned string, must resize before modifying. --- src/NimBLEUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NimBLEUtils.cpp b/src/NimBLEUtils.cpp index cd3f4fe5..b642632b 100644 --- a/src/NimBLEUtils.cpp +++ b/src/NimBLEUtils.cpp @@ -500,7 +500,7 @@ const char* NimBLEUtils::gapEventToString(uint8_t eventType) { std::string NimBLEUtils::dataToHexString(const uint8_t* source, uint8_t length) { constexpr char hexmap[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; std::string str{}; - str.reserve(length * 2 + 1); + str.resize(length * 2); for (uint8_t i = 0; i < length; i++) { str[2 * i] = hexmap[(source[i] & 0xF0) >> 4]; From 66a4f1b31b3313549864c0259d15a2948f0c7229 Mon Sep 17 00:00:00 2001 From: thekurtovic <40248206+thekurtovic@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:21:11 -0500 Subject: [PATCH 2/2] Bit shift length for resize --- src/NimBLEUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NimBLEUtils.cpp b/src/NimBLEUtils.cpp index b642632b..d69cdee9 100644 --- a/src/NimBLEUtils.cpp +++ b/src/NimBLEUtils.cpp @@ -500,7 +500,7 @@ const char* NimBLEUtils::gapEventToString(uint8_t eventType) { std::string NimBLEUtils::dataToHexString(const uint8_t* source, uint8_t length) { constexpr char hexmap[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; std::string str{}; - str.resize(length * 2); + str.resize(length << 1); for (uint8_t i = 0; i < length; i++) { str[2 * i] = hexmap[(source[i] & 0xF0) >> 4];