Skip to content

Commit cf19421

Browse files
committed
CPP: Fix FPs.
1 parent 5362fef commit cf19421

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

cpp/ql/src/Likely Bugs/Memory Management/AllocaInLoop.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,11 @@ class LoopWithAlloca extends Stmt {
322322
}
323323
}
324324

325-
from LoopWithAlloca l
325+
from LoopWithAlloca l, AllocaCall alloc
326326
where
327327
not l.(DoStmt).getCondition().getValue() = "0" and
328-
not l.isTightlyBounded()
329-
select l.getAnAllocaCall(), "Stack allocation is inside a $@ loop.", l,
328+
not l.isTightlyBounded() and
329+
alloc = l.getAnAllocaCall() and
330+
alloc.getASuccessor*() = l.(Loop).getStmt()
331+
select alloc, "Stack allocation is inside a $@ loop.", l,
330332
l.toString()

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
| AllocaInLoop1.cpp:31:18:31:23 | call to __builtin_alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1.cpp:22:2:39:2 | for(...;...;...) ... | for(...;...;...) ... |
22
| AllocaInLoop1.cpp:55:19:55:24 | call to __builtin_alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1.cpp:45:2:64:2 | for(...;...;...) ... | for(...;...;...) ... |
33
| AllocaInLoop1.cpp:80:19:80:24 | call to __builtin_alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1.cpp:71:3:88:3 | for(...;...;...) ... | for(...;...;...) ... |
4-
| AllocaInLoop1.cpp:97:19:97:24 | call to __builtin_alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1.cpp:96:2:100:13 | do (...) ... | do (...) ... |
54
| AllocaInLoop1.cpp:110:19:110:24 | call to __builtin_alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1.cpp:109:2:113:13 | do (...) ... | do (...) ... |
6-
| AllocaInLoop1.cpp:123:19:123:24 | call to __builtin_alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1.cpp:122:2:126:13 | do (...) ... | do (...) ... |
75
| AllocaInLoop1ms.cpp:28:18:28:24 | call to _alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1ms.cpp:19:2:36:2 | for(...;...;...) ... | for(...;...;...) ... |
86
| AllocaInLoop1ms.cpp:52:19:52:26 | call to _malloca | Stack allocation is inside a $@ loop. | AllocaInLoop1ms.cpp:42:2:63:2 | for(...;...;...) ... | for(...;...;...) ... |
97
| AllocaInLoop1ms.cpp:79:19:79:25 | call to _alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1ms.cpp:70:3:87:3 | for(...;...;...) ... | for(...;...;...) ... |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void case4() {
9494
char *buffer;
9595

9696
do {
97-
buffer = (char*)alloca(1024); // GOOD [FALSE POSITIVE]
97+
buffer = (char*)alloca(1024); // GOOD
9898

9999
break;
100100
} while (1);
@@ -120,7 +120,7 @@ char *case6() {
120120
char *buffer;
121121

122122
do {
123-
buffer = (char*)alloca(1024); // GOOD [FALSE POSITIVE]
123+
buffer = (char*)alloca(1024); // GOOD
124124

125125
return buffer;
126126
} while (1);

0 commit comments

Comments
 (0)