Skip to content

Commit 28f8c1c

Browse files
committed
update doc example to not use isBarrierGuard
1 parent 4bc4e08 commit 28f8c1c

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

docs/codeql/codeql-language-guides/using-flow-labels-for-precise-data-flow-analysis.rst

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,24 @@ is a barrier guard blocking flow through the use of ``data`` on the right-hand s
139139
At this point we know that ``data`` has evaluated to a truthy value, so it cannot be ``null``
140140
anymore.
141141

142-
Implementing this additional condition is easy. We implement a subclass of ``DataFlow::BarrierGuardNode``:
142+
Implementing this additional condition is easy. We implement a predicate with the following signature:
143143

144144
.. code-block:: ql
145145
146-
class TruthinessCheck extends DataFlow::BarrierGuardNode, DataFlow::ValueNode {
147-
SsaVariable v;
148-
149-
TruthinessCheck() {
150-
astNode = v.getAUse()
151-
}
152-
153-
override predicate blocks(boolean outcome, Expr e) {
154-
outcome = true and
155-
e = astNode
156-
}
146+
private predicate truthinessCheck(DataFlow::GuardNode g, ControlFlowNode node, boolean branch) {
147+
exists(SsaVariable v |
148+
g = v.getAUse() and
149+
node = g and
150+
branch = true
151+
)
157152
}
158153
159-
and then use it to override predicate ``isBarrierGuard`` in our configuration class:
154+
and then use it to override predicate ``isBarrier`` in our configuration class:
160155

161156
.. code-block:: ql
162157
163-
override predicate isBarrierGuard(DataFlow::BarrierGuardNode guard) {
164-
guard instanceof TruthinessCheck
158+
override predicate isBarrier(DataFlow::Node node) {
159+
node = DataFlow::BarrierGuard<truthinessCheck/3>::getABarrierNode()
165160
}
166161
167162
With this change, we now flag the problematic case and don't flag the unproblematic case above.

0 commit comments

Comments
 (0)