Skip to content

Commit 8b1cd98

Browse files
authored
Merge pull request ARMmbed#14574 from noonfom/string-buffer-length
Fix string buffer length in UUID trace helper
2 parents e5c79ed + 0ec4a57 commit 8b1cd98

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

connectivity/FEATURE_BLE/source/common/ble_trace_helpers.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,12 @@ const char *to_string(const UUID& uuid)
522522
static constexpr const char *HEX = "0123456789ABCDEF";
523523
static constexpr const size_t HYPHENS_DELIMITER_COUNT = 4;
524524

525-
static char string_buffer[ROW_COUNT][UUID::LENGTH_OF_LONG_UUID + HYPHENS_DELIMITER_COUNT];
525+
/*
526+
* For each hex digit, we require 2 bytes. So, we need at most 2 * 16 = 32 bytes for the hex digits.
527+
* In the case of 128-bit UUIDs, we also need space for 4 hyphen delimiters.
528+
* An additional byte is required at the end of each array to store the null terminator.
529+
*/
530+
static char string_buffer[ROW_COUNT][2 * UUID::LENGTH_OF_LONG_UUID + HYPHENS_DELIMITER_COUNT + 1];
526531
static uint8_t idx = 0;
527532

528533
++idx;

0 commit comments

Comments
 (0)