Skip to content

Commit d44761e

Browse files
authored
Merge pull request #269 from tosmolka/tosmolka/cpp/suspicious-call-to-memset
C++: support Decltype in suspicious-call-to-memset
2 parents 425d2bf + 51dcdef commit d44761e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ Type stripType(Type t) {
4141
result = stripType(t.(ArrayType).getBaseType()) or
4242
result = stripType(t.(ReferenceType).getBaseType()) or
4343
result = stripType(t.(SpecifiedType).getBaseType()) or
44+
result = stripType(t.(Decltype).getBaseType()) or
4445
(
4546
not t instanceof TypedefType and
4647
not t instanceof ArrayType and
4748
not t instanceof ReferenceType and
4849
not t instanceof SpecifiedType and
50+
not t instanceof Decltype and
4951
result = t
5052
)
5153
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,10 @@ void more_tests_2()
171171
memset(iapa, 0, sizeof(iapa)); // GOOD
172172
memset(iapa, 0, sizeof(intArrayPointer *)); // BAD
173173
}
174+
175+
void more_tests_3()
176+
{
177+
myStruct ms;
178+
decltype(&ms) msPtr = &ms;
179+
memset(msPtr, 0, sizeof(myStruct)); // GOOD
180+
}

0 commit comments

Comments
 (0)