Opened 17 years ago

Last modified 4 years ago

#1199 new enhancement

Buffer overrun not detected when variable for iteration and for access is different

Reported by: php-coderrr Owned by: noone
Priority: Normal Milestone:
Component: Improve check Version:
Keywords: arrayIndexOutOfBounds needsTest Cc:

Description (last modified by kidkat)

cppcheck (git 77c5b793c9f6433884e8c0d1bbe37db4f0db09b4) doesn't detect such buffer overflow:

[c0der@rock ~/cppcheck]$ ./cppcheck testcase.c --all
Checking testcase.c...
[c0der@rock ~/cppcheck]$ cat testcase.c
void main()
{
        char arr[50];
        int n=0;
        for (int i=0; i<100; ++i)
                arr[n++] = 0;
}

Change History (2)

comment:1 by chrchr, 4 years ago

Keywords: arrayIndexOutOfBounds added
Priority: Normal

This is detected:

void f() {
        char arr[50];
        int n=0;
        for (int i=0; i<100; ++i) {
                n = i;
                arr[n] = 0;
        }
}

comment:2 by kidkat, 4 years ago

Description: modified (diff)
Keywords: needsTest added

comment:1 has been detected since 1.38 but regressed multiple times in-between - most recently from 2.0 to 2.1.

Note: See TracTickets for help on using tickets.