Skip to content

Commit 5362fef

Browse files
committed
CPP: Additional AllocaInLoop test cases.
1 parent f12c057 commit 5362fef

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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 (...) ... |
5+
| 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 (...) ... |
47
| AllocaInLoop1ms.cpp:28:18:28:24 | call to _alloca | Stack allocation is inside a $@ loop. | AllocaInLoop1ms.cpp:19:2:36:2 | for(...;...;...) ... | for(...;...;...) ... |
58
| AllocaInLoop1ms.cpp:52:19:52:26 | call to _malloca | Stack allocation is inside a $@ loop. | AllocaInLoop1ms.cpp:42:2:63:2 | for(...;...;...) ... | for(...;...;...) ... |
69
| 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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,40 @@ void baz(const struct vtype* vec, int count) {
8888
}
8989
} while (0);
9090
}
91+
92+
// case 4: alloca contained in an unbounded loop, followed by break.
93+
void case4() {
94+
char *buffer;
95+
96+
do {
97+
buffer = (char*)alloca(1024); // GOOD [FALSE POSITIVE]
98+
99+
break;
100+
} while (1);
101+
102+
delete [] buffer;
103+
}
104+
105+
// case 5: alloca contained in an unbounded loop, followed by continue.
106+
void case5() {
107+
char *buffer;
108+
109+
do {
110+
buffer = (char*)alloca(1024); // BAD
111+
112+
continue;
113+
} while (1);
114+
115+
delete [] buffer;
116+
}
117+
118+
// case 6: alloca contained in an unbounded loop, followed by return.
119+
char *case6() {
120+
char *buffer;
121+
122+
do {
123+
buffer = (char*)alloca(1024); // GOOD [FALSE POSITIVE]
124+
125+
return buffer;
126+
} while (1);
127+
}

0 commit comments

Comments
 (0)