From aa657cd481a58c1dc5f6965708c0d12eaab41073 Mon Sep 17 00:00:00 2001 From: Rangi Date: Thu, 17 Sep 2026 10:12:02 -0400 Subject: [PATCH] Make array buffers for `snprintf` just large enough for their `uint32_t` and `uint16_t` types Note that `bank` can store 9 bytes (8 digits plus NUL terminator) even though `section.bank` should never go above 16-bit (4 digits). --- src/link/assign.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/link/assign.cpp b/src/link/assign.cpp index ee50545e..a4ee00f1 100644 --- a/src/link/assign.cpp +++ b/src/link/assign.cpp @@ -219,14 +219,14 @@ static std::optional getPlacement(Section const §ion, MemoryLocation static std::string getSectionDescription(Section const §ion) { std::string description = "\"" + section.name + "\" (" + section.typeInfo().name + " section) "; if (section.isBankFixed && section.typeInfo().isBanked()) { - char bank[8]; + char bank[9]; snprintf(bank, sizeof(bank), "%02" PRIx32, section.bank); if (section.isAddressFixed) { - char addr[8]; + char addr[5]; snprintf(addr, sizeof(addr), "%04" PRIx16, section.org); description = description + "at $" + bank + ":" + addr; } else if (section.isAlignFixed) { - char mask[8]; + char mask[5]; snprintf(mask, sizeof(mask), "%" PRIx16, static_cast(~section.alignMask)); description = description + "in bank $" + bank + " with align mask $" + mask; } else { @@ -234,11 +234,11 @@ static std::string getSectionDescription(Section const §ion) { } } else { if (section.isAddressFixed) { - char addr[8]; + char addr[5]; snprintf(addr, sizeof(addr), "%04" PRIx16, section.org); description = description + "at address $" + addr; } else if (section.isAlignFixed) { - char mask[8], offset[8]; + char mask[5], offset[5]; snprintf(mask, sizeof(mask), "%" PRIx16, static_cast(~section.alignMask)); snprintf(offset, sizeof(offset), "%" PRIx16, section.alignOfs); description = description + "with align mask $" + mask + " and offset $" + offset;