Skip to content

Commit 718f4cd

Browse files
committed
C++: Speed up SuspiciousAddWithSizeof select
This `select` clause had become very slow after we started caching `ElementBase::toString` because the query used string concatenation to produce alert messages, and those string concatenations were done very early in the pipeline, producing lots of strings that would be discarded moments later. By using `$@` to interpolate elements into strings, the concatenation is done outside of QL. Testing on a Chromium snapshot, this commit takes us from #select#ff ................ 6m2s to #select#cpe#134#fff ....... 15.2s
1 parent 7df45a9 commit 718f4cd

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

cpp/ql/src/Security/CWE/CWE-468/SuspiciousAddWithSizeof.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ where
2828
// is probably a mistake.
2929
addWithSizeof(e, sizeofExpr, _) and not isCharSzPtrExpr(e)
3030
select sizeofExpr,
31-
"Suspicious sizeof offset in a pointer arithmetic expression. " + "The type of the pointer is " +
32-
e.getFullyConverted().getType().toString() + "."
31+
"Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@.",
32+
e.getFullyConverted().getType() as t, t.toString()
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
| test.cpp:6:30:6:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
2-
| test.cpp:14:30:14:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
3-
| test.cpp:22:25:22:35 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
4-
| test.cpp:30:25:30:35 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
5-
| test.cpp:38:30:38:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
6-
| test.cpp:61:27:61:37 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is int *. |
7-
| test.cpp:89:43:89:55 | sizeof(MyABC) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is myInt *const. |
1+
| test.cpp:6:30:6:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
2+
| test.cpp:14:30:14:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
3+
| test.cpp:22:25:22:35 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
4+
| test.cpp:30:25:30:35 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
5+
| test.cpp:38:30:38:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
6+
| test.cpp:61:27:61:37 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
7+
| test.cpp:89:43:89:55 | sizeof(MyABC) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | myInt *const | myInt *const |

0 commit comments

Comments
 (0)