Content-Length: 281152 | pFad | http://github.com/micropython/micropython/pull/17739

F4 py/objint_longlong: Fix overflow check in mp_obj_int_get_checked. by yoctopuce · Pull Request #17739 · micropython/micropython · GitHub
Skip to content

py/objint_longlong: Fix overflow check in mp_obj_int_get_checked. #17739

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

This is to fix an outstanding TODO. The test cases is using a range expression, as this is available all builds, but mp_obj_get_int is used by various extmod where an overflow is more likely to occur.

Testing

The code is pretty simple, and has been tested on unix/longlong varient.
An test case has been added in CI tests.

Trade-offs and Alternatives

I am not sure that this exception is likely to occur in the MicroPython core code ,unless the Python code includes a serious bug. Therefore, the extra code size might not be worthwhile for everyone. However, there are many hardware extensions that use this function, and in those cases, the likelihood of an overflow is much higher.

This is to fix an outstanding TODO. The test cases is using a
range as this will exist in all builds, but mp_obj_get_int
is used in many different parts of code where an overflow
is more likely to occur.

Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.41%. Comparing base (e993f53) to head (fc5cbad).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17739   +/-   ##
=======================================
  Coverage   98.41%   98.41%           
=======================================
  Files         171      171           
  Lines       22210    22210           
=======================================
  Hits        21857    21857           
  Misses        353      353           

☔ 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.

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@yoctopuce
Copy link
Contributor Author

@dpgeorge Can you help me understand what could cause zephir port to cause a syntax error when compiling int_64_basics.py ?
I have the impression that the new code is super safe... Could it be a problem with constant folding of the expression 1 << 32 ?

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








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/micropython/micropython/pull/17739

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy