C++: Add tests for three FPs observed on lgtm.com

This commit is contained in:
Jonas Jensen
2019-03-16 20:11:01 +01:00
parent af1c502b11
commit 1a7351ef6e
2 changed files with 24 additions and 0 deletions

View File

@@ -5,3 +5,6 @@
| test.cpp:92:2:92:12 | return ... | May return stack-allocated memory from $@. | test.cpp:89:10:89:11 | mc | mc |
| test.cpp:112:2:112:12 | return ... | May return stack-allocated memory from $@. | test.cpp:112:9:112:11 | arr | arr |
| test.cpp:119:2:119:19 | return ... | May return stack-allocated memory from $@. | test.cpp:119:11:119:13 | arr | arr |
| test.cpp:149:3:149:22 | return ... | May return stack-allocated memory from $@. | test.cpp:149:11:149:21 | threadLocal | threadLocal |
| test.cpp:155:3:155:18 | return ... | May return stack-allocated memory from $@. | test.cpp:154:19:154:26 | localInt | localInt |
| test.cpp:165:3:165:19 | return ... | May return stack-allocated memory from $@. | test.cpp:164:21:164:28 | localBuf | localBuf |

View File

@@ -143,3 +143,24 @@ char *testArray5()
return arr; // GOOD
}
int *returnThreadLocal() {
thread_local int threadLocal;
return &threadLocal; // GOOD [FALSE POSITIVE]
}
int returnDereferenced() {
int localInt = 2;
int &localRef = localInt;
return localRef; // GOOD [FALSE POSITIVE]
}
typedef unsigned long size_t;
void *memcpy(void *s1, const void *s2, size_t n);
char *returnAfterCopy() {
char localBuf[] = "Data";
static char staticBuf[sizeof(localBuf)];
memcpy(staticBuf, localBuf, sizeof(staticBuf));
return staticBuf; // GOOD [FALSE POSITIVE]
}