C++: Add testcases with false positives.

This commit is contained in:
Mathias Vorreiter Pedersen
2021-05-18 17:44:08 +02:00
parent ae6326b1f3
commit df9981de4f
2 changed files with 20 additions and 0 deletions

View File

@@ -5,6 +5,8 @@
| tests.cpp:245:42:245:42 | 6 | Potential buffer-overflow: 'global_array_5' has size 5 not 6. |
| tests.cpp:349:2:349:14 | access to array | Potential buffer-overflow: 'charArray' has size 10 but 'charArray[10]' is accessed here. |
| tests.cpp:350:17:350:29 | access to array | Potential buffer-overflow: 'charArray' has size 10 but 'charArray[10]' is accessed here. |
| tests.cpp:594:4:594:12 | access to array | Potential buffer-overflow: counter 'k' <= 100 but 'buffer' has 16 elements. |
| tests.cpp:603:24:603:24 | n | Potential buffer-overflow: 'dest' has size 128 not 132. |
| var_size_struct.cpp:54:5:54:14 | access to array | Potential buffer-overflow: 'str' has size 1 but 'str[1]' is accessed here. |
| var_size_struct.cpp:55:5:55:14 | access to array | Potential buffer-overflow: 'str' has size 1 but 'str[1]' is accessed here. |
| var_size_struct.cpp:103:39:103:41 | 129 | Potential buffer-overflow: 'str' has size 128 not 129. |

View File

@@ -586,6 +586,23 @@ void test21(bool cond)
if (ptr[-1] == 0) { return; } // GOOD: accesses buffer[1]
}
void test22(bool b, const char* source) {
char buffer[16];
int k;
for (k = 0; k <= 100; k++) {
if(k < 16) {
buffer[k] = 'x'; // GOOD [FALSE POSITIVE]
}
}
char dest[128];
int n = b ? 1024 : 132;
if (n >= 128) {
return;
}
memcpy(dest, source, n); // GOOD [FALSE POSITIVE]
}
int main(int argc, char *argv[])
{
long long arr17[19];
@@ -609,6 +626,7 @@ int main(int argc, char *argv[])
test19(argc == 0);
test20();
test21(argc == 0);
test22(argc == 0, argv[0]);
return 0;
}