Skip to content

Commit 1a7351e

Browse files
committed
C++: Add tests for three FPs observed on lgtm.com
1 parent af1c502 commit 1a7351e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/ReturnStackAllocatedMemory.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
| test.cpp:92:2:92:12 | return ... | May return stack-allocated memory from $@. | test.cpp:89:10:89:11 | mc | mc |
66
| test.cpp:112:2:112:12 | return ... | May return stack-allocated memory from $@. | test.cpp:112:9:112:11 | arr | arr |
77
| test.cpp:119:2:119:19 | return ... | May return stack-allocated memory from $@. | test.cpp:119:11:119:13 | arr | arr |
8+
| test.cpp:149:3:149:22 | return ... | May return stack-allocated memory from $@. | test.cpp:149:11:149:21 | threadLocal | threadLocal |
9+
| test.cpp:155:3:155:18 | return ... | May return stack-allocated memory from $@. | test.cpp:154:19:154:26 | localInt | localInt |
10+
| test.cpp:165:3:165:19 | return ... | May return stack-allocated memory from $@. | test.cpp:164:21:164:28 | localBuf | localBuf |

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,24 @@ char *testArray5()
143143

144144
return arr; // GOOD
145145
}
146+
147+
int *returnThreadLocal() {
148+
thread_local int threadLocal;
149+
return &threadLocal; // GOOD [FALSE POSITIVE]
150+
}
151+
152+
int returnDereferenced() {
153+
int localInt = 2;
154+
int &localRef = localInt;
155+
return localRef; // GOOD [FALSE POSITIVE]
156+
}
157+
158+
typedef unsigned long size_t;
159+
void *memcpy(void *s1, const void *s2, size_t n);
160+
161+
char *returnAfterCopy() {
162+
char localBuf[] = "Data";
163+
static char staticBuf[sizeof(localBuf)];
164+
memcpy(staticBuf, localBuf, sizeof(staticBuf));
165+
return staticBuf; // GOOD [FALSE POSITIVE]
166+
}

0 commit comments

Comments
 (0)