Skip to content

Commit 6cdfaee

Browse files
committed
CPP: getAChild() -> getAChild*().
1 parent 01611d4 commit 6cdfaee

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

cpp/ql/src/Best Practices/Likely Errors/OffsetUseBeforeRangeCheck.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import cpp
1515

1616
from Variable v, LogicalAndExpr andexpr, ArrayExpr access, LTExpr rangecheck
1717
where access.getArrayOffset() = v.getAnAccess()
18-
and andexpr.getLeftOperand().getAChild() = access
18+
and andexpr.getLeftOperand().getAChild*() = access
1919
and andexpr.getRightOperand() = rangecheck
2020
and rangecheck.getLeftOperand() = v.getAnAccess()
2121
and not access.isInMacroExpansion()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
| test.cpp:11:10:11:18 | access to array | This use of offset 'i' should follow the $@. | test.cpp:11:32:11:45 | ... < ... | range check |
22
| test.cpp:15:7:15:15 | access to array | This use of offset 'i' should follow the $@. | test.cpp:15:29:15:42 | ... < ... | range check |
3+
| test.cpp:27:7:27:15 | access to array | This use of offset 'i' should follow the $@. | test.cpp:27:39:27:52 | ... < ... | range check |
4+
| test.cpp:32:27:32:35 | access to array | This use of offset 'i' should follow the $@. | test.cpp:32:49:32:66 | ... < ... | range check |
35
| test.cpp:33:28:33:36 | access to array | This use of offset 'i' should follow the $@. | test.cpp:33:50:33:67 | ... < ... | range check |
6+
| test.cpp:34:31:34:39 | access to array | This use of offset 'i' should follow the $@. | test.cpp:34:53:34:66 | ... < ... | range check |
47
| test.cpp:35:32:35:40 | access to array | This use of offset 'i' should follow the $@. | test.cpp:35:54:35:67 | ... < ... | range check |
58
| test.cpp:39:8:39:16 | access to array | This use of offset 'i' should follow the $@. | test.cpp:39:30:39:47 | ... < ... | range check |
9+
| test.cpp:44:7:44:15 | access to array | This use of offset 'i' should follow the $@. | test.cpp:44:22:44:35 | ... < ... | range check |
10+
| test.cpp:47:7:47:15 | access to array | This use of offset 'i' should follow the $@. | test.cpp:47:33:47:46 | ... < ... | range check |

cpp/ql/test/query-tests/Best Practices/Likely Errors/OffsetUseBeforeRangeCheck/test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ void test(char *buffer, int bufferSize)
2424
if ((buffer[i] == 'x') && (bufferSize >= i + 1)) {} // BAD [NOT DETECTED]
2525

2626
if ((i < bufferSize) && (true) && (buffer[i] == 'x')) {} // GOOD
27-
if ((buffer[i] == 'x') && (true) && (i < bufferSize)) {} // BAD [NOT DETECTED]
27+
if ((buffer[i] == 'x') && (true) && (i < bufferSize)) {} // BAD
2828

2929
if ((i < bufferSize - 1) && (buffer[i + 1] == 'x')) {} // GOOD
3030
if ((buffer[i + 1] == 'x') && (i < bufferSize - 1)) {} // BAD [NOT DETECTED]
3131

32-
if ((i < bufferSize) && (buffer[i] == 'x') && (i < bufferSize - 1)) {} // GOOD
32+
if ((i < bufferSize) && (buffer[i] == 'x') && (i < bufferSize - 1)) {} // GOOD [FALSE POSITIVE]
3333
if ((i < bufferSize) && ((buffer[i] == 'x') && (i < bufferSize - 1))) {} // GOOD [FALSE POSITIVE]
34-
if ((i < bufferSize + 1) && (buffer[i] == 'x') && (i < bufferSize)) {} // BAD [NOT DETECTED]
34+
if ((i < bufferSize + 1) && (buffer[i] == 'x') && (i < bufferSize)) {} // BAD
3535
if ((i < bufferSize + 1) && ((buffer[i] == 'x') && (i < bufferSize))) {} // BAD
3636

3737
// look for 'ab'
@@ -41,10 +41,10 @@ void test(char *buffer, int bufferSize)
4141
}
4242

4343
if ((i < bufferSize) && (buffer[i])) {} // GOOD
44-
if ((buffer[i]) && (i < bufferSize)) {} // BAD [NOT DETECTED]
44+
if ((buffer[i]) && (i < bufferSize)) {} // BAD
4545

4646
if ((i < bufferSize) && (buffer[i] + 1 == 'x')) {} // GOOD
47-
if ((buffer[i] + 1 == 'x') && (i < bufferSize)) {} // BAD [NOT DETECTED]
47+
if ((buffer[i] + 1 == 'x') && (i < bufferSize)) {} // BAD
4848

4949
if ((buffer != 0) && (i < bufferSize)) {} // GOOD
5050
}

0 commit comments

Comments
 (0)