micropython / micropython/micropython

Overflow converting -2147483648 to int when using MPZ

Open
#6,332 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

py-core
Dominant language
C
Stars
22.1k
Forks
9k
Avg merge
6d 4h
Merged PRs (30d)
16

Description

When MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ, calling mp_obj_get_int() for a Python variable that contains the value -2147483648 results in an overflow converting long int to machine word error.

If MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG instead, the conversion works OK.

Is the MPZ overflow check incorrect?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating mp_obj_get_int() and the MPZ implementation of integer-to-machine-word conversion, then compare its boundary handling with the LONGLONG path. Reproduce the conversion for -2147483648 with MICROPY_LONGINT_IMPL_MPZ enabled and verify that the value no longer raises an overflow error.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.