Skip to content

Commit cea1049

Browse files
authored
Merge pull request github#5249 from geoffw0/cleanupstr
C++: QLDoc Pure.qll
2 parents bf66bdb + 358a8fe commit cea1049

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
467467
// ... and likewise for destructors.
468468
this.(Destructor).getADestruction().mayBeGloballyImpure()
469469
else
470-
// Unless it's a function that we know is side-effect-free, it may
470+
// Unless it's a function that we know is side-effect free, it may
471471
// have side-effects.
472472
not this.hasGlobalOrStdName([
473473
"strcmp", "wcscmp", "_mbscmp", "strlen", "wcslen", "_mbslen", "_mbslen_l", "_mbstrlen",

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import semmle.code.cpp.models.interfaces.Taint
33
import semmle.code.cpp.models.interfaces.Alias
44
import semmle.code.cpp.models.interfaces.SideEffect
55

6-
/** Pure string functions. */
6+
/**
7+
* A function that operates on strings and is pure. That is, its evaluation is
8+
* guaranteed to be side-effect free.
9+
*/
710
private class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunction,
811
SideEffectFunction {
912
PureStrFunction() {
@@ -89,7 +92,9 @@ private string strcmp() {
8992
]
9093
}
9194

92-
/** String standard `strlen` function, and related functions for computing string lengths. */
95+
/**
96+
* A function such as `strlen` that returns the length of the given string.
97+
*/
9398
private class StrLenFunction extends AliasFunction, ArrayFunction, SideEffectFunction {
9499
StrLenFunction() {
95100
hasGlobalOrStdOrBslName(["strlen", "strnlen", "wcslen"])
@@ -123,7 +128,10 @@ private class StrLenFunction extends AliasFunction, ArrayFunction, SideEffectFun
123128
}
124129
}
125130

126-
/** Pure functions. */
131+
/**
132+
* A function that is pure, that is, its evaluation is guaranteed to be
133+
* side-effect free. Excludes functions modeled by `PureStrFunction` and `PureMemFunction`.
134+
*/
127135
private class PureFunction extends TaintFunction, SideEffectFunction {
128136
PureFunction() { hasGlobalOrStdOrBslName(["abs", "labs"]) }
129137

@@ -140,7 +148,10 @@ private class PureFunction extends TaintFunction, SideEffectFunction {
140148
override predicate hasOnlySpecificWriteSideEffects() { any() }
141149
}
142150

143-
/** Pure raw-memory functions. */
151+
/**
152+
* A function that operates on memory buffers and is pure. That is, its
153+
* evaluation is guaranteed to be side-effect free.
154+
*/
144155
private class PureMemFunction extends AliasFunction, ArrayFunction, TaintFunction,
145156
SideEffectFunction {
146157
PureMemFunction() {

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ class Expr extends @expr, ExprOrStmt, ExprOrType, AST::ValueNode {
115115
predicate isImpure() { any() }
116116

117117
/**
118-
* Holds if this expression is pure, that is, is its evaluation is guaranteed to be
119-
* side effect-free.
118+
* Holds if this expression is pure, that is, is its evaluation is guaranteed
119+
* to be side-effect free.
120120
*/
121121
predicate isPure() { not isImpure() }
122122

0 commit comments

Comments
 (0)