Skip to content

Commit 3532d6b

Browse files
authored
Merge pull request #169 from airbornemint/dbgDumpMemory-beyond-255
Fixed output of dbgDumpMemory when buffer size > 255 bytes
2 parents 35d9fb0 + 02c79ff commit 3532d6b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cores/nRF5/debug.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,15 @@ void dbgPrintVersion(void)
177177
void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffset)
178178
{
179179
uint8_t const *buf8 = (uint8_t const *) buf;
180+
181+
uint8_t format_size = 2 * size;
182+
if ( count*size > UINT8_MAX ) offset_fmt_size *= 2;
183+
if ( count*size > UINT16_MAX ) offset_fmt_size *= 2;
180184

181-
char format[] = "%00lX";
182-
format[2] += 2*size;
185+
char format[] = "%02lX";
183186

184-
char offset_fmt[] = "%02lX: ";
185-
186-
if ( count*size > UINT8_MAX ) format[2] *= 2;
187-
if ( count*size > UINT16_MAX ) format[2] *= 2;
187+
char offset_fmt[] = "%00lX: ";
188+
offset_fmt[2] += offset_fmt_size;
188189

189190
const uint8_t item_per_line = 16 / size;
190191

0 commit comments

Comments
 (0)