Last active
August 28, 2019 12:42
-
-
Save anatolyborodin/0efc6e58536721603930de89d60325ee to your computer and use it in GitHub Desktop.
cppcheck bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define ARR_SIZE 10 | |
int arr[ARR_SIZE]; | |
static int f(int v) | |
{ | |
int i; | |
int found = 0; | |
for (i = 0; i < ARR_SIZE; ++i) { | |
if (arr[i] == v) { | |
found = 1; | |
break; | |
} | |
} | |
if (!found) { | |
return -1; | |
} | |
arr[i] = 0; | |
return i; | |
} | |
int main() | |
{ | |
int i; | |
for (i = 0; i < ARR_SIZE; ++i) { | |
arr[i] = i * i * i; | |
} | |
printf("f(125) = %d\n", f(125)); | |
printf("Try again...\n"); | |
printf("f(125) = %d\n", f(125)); | |
} | |
/* cppcheck 1.86-1 (Ubuntu 19.04) says: | |
# cppcheck test.c | |
Checking test.c ... | |
[test.c:20]: (error) Array 'arr[10]' accessed at index 10, which is out of bounds. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment