Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR resolves the formatting issues in the custom
core::vsnprintimplementation.Changes
print_numberandprint_signed_numberinvsnprint.cppto correctly support width, padding, uppercase hex, and signs.core::vsnprintformat parser to handle leading zero flags (0) and widths before type/length modifiers.%X(uppercase hex without a prepended prefix).%xand%bto account for their prepended prefixes.catch2-vsnprint.cppto verify all formatting.Closes #33