micropython / micropython/micropython
Incorrect loop conditional
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 22.1k
- Forks
- 9k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 16
Description
I came across a problem while experimenting with MicroPython (v1.9.4). The program crashed while trying to execute this while loop:
while (--d >= dig) {
a = (a << DIG_SIZE) | *d;
*d = a / base;
a %= base;
}
The pre-decrement (i.e. --) operation underflows the d pointer which caused the d >= dig condition to succeed (even though it shouldn't). Therefore, the line
*d = a / base
was mistakenly executed using an out-of-bounds pointer d.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in py/mpz.c at the loop around line 1705 and trace the bounds of d through the pre-decrement and comparison. Reproduce the MicroPython v1.9.4 crash described in the issue, then verify that the loop no longer dereferences an out-of-bounds pointer while preserving the intended calculation.
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
- Clearly specified
- Newbie friendliness
- 45/100