Skip to content

Fix custom vsnprint formatting for width, leading zeros, and %X#34

Merged
emrainey merged 1 commit into
developfrom
issue-33
Jun 27, 2026
Merged

Fix custom vsnprint formatting for width, leading zeros, and %X#34
emrainey merged 1 commit into
developfrom
issue-33

Conversation

@emrainey

Copy link
Copy Markdown
Owner

This PR resolves the formatting issues in the custom core::vsnprint implementation.

Changes

  • Enhanced print_number and print_signed_number in vsnprint.cpp to correctly support width, padding, uppercase hex, and signs.
  • Updated core::vsnprint format parser to handle leading zero flags (0) and widths before type/length modifiers.
  • Added support for %X (uppercase hex without a prepended prefix).
  • Adjusted width calculations for %x and %b to account for their prepended prefixes.
  • Added Catch2 unit tests in catch2-vsnprint.cpp to verify all formatting.

Closes #33

Related To Issue: 33

What's Wrong:

* The custom core::vsnprint parser did not handle leading zero flags
  or width limits. As a result, formatting strings like "%02X" failed,
  resulting in malformed output (such as "?2X:?2X:..." on boot for
  the Ethernet MAC address).
* The custom parser only supported lowercase hexadecimal ("%x")
  and always prepended "0x", which prevented printing uppercase raw
  hex values without prefixes.

How Was it Fixed (if not obvious):

* Enhanced print_number and print_signed_number in vsnprint.cpp to
  support width, space/zero padding, uppercase hex, and correct signs.
* Updated vsnprint format parser to parse leading zero flags and
  widths prior to length modifiers.
* Added support for "%X" specifier (uppercase hex without
  prepending "0x").
* Adjusted width calculations for "%x" and "%b" to account for their
  prepended prefixes.
* Added Catch2 unit tests in catch2-vsnprint.cpp to verify formatting.
* AI generated the code modifications and unit tests, and a human
  reviewed the changes, built target presets, and made this commit.

What side effects does this have (could be none):

* None. Existing calls to %x and other formatting specifiers preserve
  their exact original behavior.

Which builds did you run to make sure they build?

[x] arm-none-eabi-gcc Cortex M4
[x] arm-none-eabi-gcc Cortex M7
[x] (Apple) Native Clang
[ ] (Apple) Homebrew GCC
[x] (Apple) Homebrew LLVM

How Do We Know and Can Show It's Fixed:

* Verified by 100% passing results of the new vsnprint Catch2 tests in
  the test-core-none-all host suite.

Which Unittest Series did you Check?

[x] (Apple) Native Clang
[ ] (Apple) Homebrew GCC
[x] (Apple) Homebrew LLVM

Did this affect any on-target builds? If so which were tested?

[ ] STM32F407VE board
[ ] STM32H753ZI board
@emrainey emrainey merged commit d8bfd02 into develop Jun 27, 2026
1 of 4 checks passed
@emrainey emrainey deleted the issue-33 branch June 27, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant