Skip to content

Commit 2ca52a4

Browse files
committed
[zlaski/memset-model] Add side effect modeling to Memset.
1 parent a0cbd87 commit 2ca52a4

File tree

1 file changed

+13
-1
lines changed
  • cpp/ql/src/semmle/code/cpp/models/implementations

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import semmle.code.cpp.Function
22
import semmle.code.cpp.models.interfaces.ArrayFunction
33
import semmle.code.cpp.models.interfaces.DataFlow
44
import semmle.code.cpp.models.interfaces.Alias
5+
import semmle.code.cpp.models.interfaces.SideEffect
56

67
/**
78
* The standard function `memset` and its assorted variants
89
*/
9-
class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction {
10+
class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction, SideEffectFunction {
1011
MemsetFunction() {
1112
hasGlobalName("memset") or
1213
hasGlobalName("wmemset") or
@@ -38,4 +39,15 @@ class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction {
3839
override predicate parameterIsAlwaysReturned(int index) {
3940
not hasGlobalName("bzero") and index = 0
4041
}
42+
43+
override predicate hasOnlySpecificReadSideEffects() { any() }
44+
override predicate hasOnlySpecificWriteSideEffects() { any() }
45+
46+
override predicate hasSpecificWriteSideEffect(ParameterIndex i, boolean buffer, boolean mustWrite) {
47+
i = 0 and buffer = true and mustWrite = true
48+
}
49+
50+
override ParameterIndex getParameterSizeIndex(ParameterIndex i) {
51+
i = 0 and if hasGlobalName("bzero") then result = 1 else result = 2
52+
}
4153
}

0 commit comments

Comments
 (0)