Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f087ff3

Browse files
authored
Merge pull request #5167 from criemen/bsl-memset
C++: Refactor Mem*.qll and include bsl model.
2 parents bf401c7 + 434a5f0 commit f087ff3

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

cpp/ql/src/semmle/code/cpp/Declaration.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ class Declaration extends Locatable, @declaration {
139139
this.hasQualifiedName("std", "", name)
140140
}
141141

142+
/**
143+
* Holds if this declaration has the given name in the global namespace,
144+
* the `std` namespace or the `bsl` namespace.
145+
* We treat `std` and `bsl` as the same in some of our models.
146+
*/
147+
predicate hasGlobalOrStdOrBslName(string name) {
148+
this.hasGlobalName(name)
149+
or
150+
this.hasQualifiedName("std", "", name)
151+
or
152+
this.hasQualifiedName("bsl", "", name)
153+
}
154+
142155
/** Gets a specifier of this declaration. */
143156
Specifier getASpecifier() { none() } // overridden in subclasses
144157

cpp/ql/src/semmle/code/cpp/models/implementations/Memcpy.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private class MemcpyFunction extends ArrayFunction, DataFlowFunction, SideEffect
2020
// memcpy(dest, src, num)
2121
// memmove(dest, src, num)
2222
// memmove(dest, src, num, remaining)
23-
this.hasGlobalOrStdName(["memcpy", "memmove"])
23+
this.hasGlobalOrStdOrBslName(["memcpy", "memmove"])
2424
or
2525
// bcopy(src, dest, num)
2626
// mempcpy(dest, src, num)

cpp/ql/src/semmle/code/cpp/models/implementations/Memset.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import semmle.code.cpp.models.interfaces.SideEffect
1515
private class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction,
1616
SideEffectFunction {
1717
MemsetFunction() {
18-
this.hasGlobalOrStdName(["memset", "wmemset"])
18+
this.hasGlobalOrStdOrBslName("memset")
19+
or
20+
this.hasGlobalOrStdName("wmemset")
1921
or
2022
this.hasGlobalName([bzero(), "__builtin_memset", "__builtin_memset_chk"])
2123
}

0 commit comments

Comments
 (0)