Skip to content

Incorrect loop conditional #6066

@andresag01

Description

@andresag01

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    py-coreRelates to py/ directory in source

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions