mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
C++: suppress alerts in tightly bounded loops
This commit is contained in:
@@ -6,3 +6,12 @@
|
||||
| AllocaInLoop1ms.cpp:79:19:79:25 | call to _alloca | Stack allocation is inside a $@ and could lead to stack overflow. | AllocaInLoop1ms.cpp:70:3:87:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
| AllocaInLoop2.c:39:30:39:35 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | AllocaInLoop2.c:29:5:48:19 | do (...) ... | do (...) ... |
|
||||
| AllocaInLoop3.cpp:45:23:45:28 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | AllocaInLoop3.cpp:43:2:49:19 | do (...) ... | do (...) ... |
|
||||
| BoundedLoop.cpp:25:5:25:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:24:3:26:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
| BoundedLoop.cpp:38:5:38:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:37:3:39:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
| BoundedLoop.cpp:55:5:55:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:54:3:59:3 | while (...) ... | while (...) ... |
|
||||
| BoundedLoop.cpp:64:5:64:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:63:3:68:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
| BoundedLoop.cpp:73:5:73:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:72:3:74:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
| BoundedLoop.cpp:97:5:97:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:96:3:98:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
| BoundedLoop.cpp:105:5:105:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:104:3:106:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
| BoundedLoop.cpp:138:5:138:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:137:3:139:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
| BoundedLoop.cpp:176:5:176:10 | call to __builtin_alloca | Stack allocation is inside a $@ and could lead to stack overflow. | BoundedLoop.cpp:175:3:177:3 | for(...;...;...) ... | for(...;...;...) ... |
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
void *__builtin_alloca(unsigned long sz);
|
||||
#define alloca __builtin_alloca
|
||||
|
||||
void forOnce() {
|
||||
for (struct { bool stop; } state = { 0 }; !state.stop; state.stop = 1) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void forOnce2() {
|
||||
bool stop;
|
||||
for (stop = 0; !stop; stop = 1) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void forTwice() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void forEver() {
|
||||
for (;;) {
|
||||
alloca(100); // BAD
|
||||
}
|
||||
}
|
||||
|
||||
void doTwice() {
|
||||
int i = 0;
|
||||
do {
|
||||
alloca(100); // GOOD
|
||||
} while (++i < 2);
|
||||
}
|
||||
|
||||
void unknownStartingPoint(int i) {
|
||||
for (; i < 2; i++) {
|
||||
alloca(100); // BAD
|
||||
}
|
||||
}
|
||||
|
||||
int getInt();
|
||||
|
||||
void atMostTwice() {
|
||||
int i = 0;
|
||||
while (!(i >= 2 || getInt())) {
|
||||
i++;
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void sometimesIncrement() {
|
||||
int i = 0;
|
||||
while (i < 2) {
|
||||
alloca(100); // BAD
|
||||
if (getInt()) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void upAndDown() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
alloca(100); // BAD
|
||||
if (getInt()) {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void largeBound() {
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
alloca(100); // BAD
|
||||
}
|
||||
}
|
||||
|
||||
void largeOffset() {
|
||||
int i;
|
||||
if (getInt()) {
|
||||
i = 9998;
|
||||
} else {
|
||||
i = 9997;
|
||||
}
|
||||
for (; i < 10000; i++) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void maybeSmallOffset() {
|
||||
int i;
|
||||
if (getInt()) {
|
||||
i = 0;
|
||||
} else {
|
||||
i = 9997;
|
||||
}
|
||||
for (; i < 10000; i++) {
|
||||
alloca(100); // BAD
|
||||
}
|
||||
}
|
||||
|
||||
void incBefore() {
|
||||
int i = -1;
|
||||
i++; // not understood by data flow
|
||||
for (; i < 2; i++) {
|
||||
alloca(100); // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
}
|
||||
|
||||
void nestedAddsUp() {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
alloca(100); // BAD [NOT DETECTED]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nestedWithReset() {
|
||||
bool stop = 0;
|
||||
|
||||
for (int i = 0; i < 1; i++) {
|
||||
stop = 0;
|
||||
do {
|
||||
stop = 1;
|
||||
alloca(100); // GOOD
|
||||
} while (!stop);
|
||||
stop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void eqFalse() {
|
||||
for (int stop = 0; stop == 0; stop = 5) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void eqFalseFlipped() {
|
||||
for (int stop = 0; stop == 0; stop = 0) {
|
||||
alloca(100); // BAD
|
||||
}
|
||||
}
|
||||
|
||||
void neFalse() {
|
||||
for (bool go_on = true; go_on != 0; go_on = false) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void eqTrue() {
|
||||
for (bool go_on = false; go_on == true; go_on = false) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void countDownFor() {
|
||||
for (int i = 2; i >= 0; i--) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void countDownWhile() {
|
||||
int i;
|
||||
i = 2;
|
||||
while (--i >= 0) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void countDownAssignAdd() {
|
||||
for (int i = 2; i >= 0; i = i - 1) {
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
void countDownWrong() {
|
||||
for (int i = 2-1; i >= 0; i++) {
|
||||
alloca(100); // BAD
|
||||
}
|
||||
}
|
||||
|
||||
void countUpFromUnsigned(unsigned long i) {
|
||||
while (i < 10) {
|
||||
i = i + 1;
|
||||
alloca(100); // GOOD
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user