libs/libc: support explicit bases up to 36 - #19594
Merged
Merged
Conversation
The strto* interfaces document explicit bases in the range 2 through 36, and lib_isbasedigit() already supports alphabetic digits through base 36. However, lib_checkbase() rejects every explicit base above 26 with EINVAL. Raise the validation limit to 36 so the conversion interfaces accept the full documented range while continuing to reject base 37 and above. Signed-off-by: hanzhijian <hanzhijian@zepp.com>
Zepp-Hanzj
force-pushed
the
fix/libc-strto-base36
branch
from
August 1, 2026 06:38
a5b143f to
9ea7bc4
Compare
|
acassis
approved these changes
Aug 1, 2026
Contributor
|
@Zepp-Hanzj suggestion: add some test to it on ostest |
Contributor
Author
|
Thanks for the suggestion. I added dedicated ostest regression coverage in apache/nuttx-apps#3688. It checks every explicit base from 2 through 36, lower- and upper-case digits, all six strto* interfaces, end pointers, errno, and invalid bases 1 and 37. I verified that it asserts at the first base-27 case without this fix and passes the libc test section with this fix. |
Zepp-Hanzj
marked this pull request as ready for review
August 1, 2026 09:58
xiaoxiang781216
approved these changes
Aug 1, 2026
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.
Summary
The integer conversion interfaces document explicit bases from 2 through 36. The shared
lib_checkbase()helper currently rejects bases above 26 even thoughlib_isbasedigit()already supports digits0-9and lettersa-z/A-Z.Raise the explicit-base limit from 26 to 36 so
strtol(),strtoul(),strtoll(),strtoull(),strtoimax(), andstrtoumax()accept the full documented range. Bases below 2 and above 36 remain invalid.Impact
Explicit bases 27 through 36 no longer fail with
EINVAL. Existing base-0 detection, bases 2 through 26, and invalid-base handling are unchanged.Testing
Automated regression coverage
apache/nuttx-apps#3688 adds dedicated
ostestcoverage for bases 2 through36, all six
strto*interfaces, end pointers,errno, and invalid bases 1and 37. The test asserts at base 27 without this fix and passes with it.
NuttX sim
Built the current upstream
sim:nshconfiguration and ran a dedicated 117-assertion test program covering:STM32F407ZG hardware A/B
Built and flashed the same 110-assertion test program before and after this one-line change. J-Link verified both images after programming. The serial results below are from the physical STM32F407ZG target at 115200 baud.
Before fix: 69 passed, 41 failed
After fix: 110 passed, 0 failed
Style