tests/extmod/json_loads: Add test cases for LONGINT parse.#16931
Closed
yoctopuce wants to merge 1 commit intomicropython:masterfrom
Closed
tests/extmod/json_loads: Add test cases for LONGINT parse.#16931yoctopuce wants to merge 1 commit intomicropython:masterfrom
yoctopuce wants to merge 1 commit intomicropython:masterfrom
Conversation
These tests cover the use of mp_obj_new_int_from_str_len when mp_parse_num_integer overlows the SMALLINT limit. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #16931 +/- ##
=======================================
Coverage 98.54% 98.54%
=======================================
Files 169 169
Lines 21877 21877
=======================================
Hits 21558 21558
Misses 319 319 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
Thanks for the test case! I've cherry-picked and incorporated it into #16953. |
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
These tests cover the use of
mp_obj_new_int_from_str_lenwhenmp_parse_num_integeroverlows the SMALLINT limit.I recently discovered that the
LONGLONGimplementation ofmp_obj_new_int_from_str_lenis broken. It does not take the sign into account, and assumes the string buffer is nul-terminated, which is wrong asmp_parse_num_integeris mostly used onvstrbuffers.However, there is currently no test case that checks for these specific aspects of overflow handling: when integration tests are run with MICROPY_LONGINT_IMPL set to MICROPY_LONGINT_IMPL_LONGLONG, all tests pass.
So this pull requests adds coverage for these corner cases.
As there is currently no variant that uses MICROPY_LONGINT_IMPL_LONGLONG in the standard integration tests, adding these test cases will not cause a build issue.
Adding a MICROPY_LONGINT_IMPL_LONGLONG variant to the integration tests and fixing the longlong parsing code should be discussed first and handled in separate pull requests, but at least these test cases will properly document the problematic cases.
Testing
This code test code has been tested on Unix ports (LONGLONG and MPZ).
With MPZ, the test case pass
With LONGLONG, the test case fails