Skip to content

tests/extmod/json_loads: Add test cases for LONGINT parse. #16931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yoctopuce
Copy link
Contributor

Summary

These tests cover the use of mp_obj_new_int_from_str_len when mp_parse_num_integer overlows the SMALLINT limit.

I recently discovered that the LONGLONG implementation of mp_obj_new_int_from_str_len is broken. It does not take the sign into account, and assumes the string buffer is nul-terminated, which is wrong as mp_parse_num_integer is mostly used on vstr buffers.

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

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>
Copy link

codecov bot commented Mar 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (f187c77) to head (92da2c5).
Report is 39 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@projectgus
Copy link
Contributor

Thanks for the test case! I've cherry-picked and incorporated it into #16953.

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Relates to tests/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants