Skip to content

Commit a692ba7

Browse files
committed
Format message and finish final draft
1 parent d254ec2 commit a692ba7

File tree

2 files changed

+483
-209
lines changed

2 files changed

+483
-209
lines changed

cpp/misra/src/rules/RULE-8-7-1/PointerArithmeticFormsAnInvalidPointer.ql

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,22 @@ module TrackArray = DataFlow::Global<TrackArrayConfig>;
389389

390390
import TrackArray::PathGraph
391391

392-
from TrackArray::PathNode src, TrackArray::PathNode sink, FatPointer end, string message
392+
from
393+
TrackArray::PathNode src, TrackArray::PathNode sink, FatPointer end, int totalOffset, int length
393394
where
394395
not isExcluded(sink.getNode().asExpr(),
395396
Memory1Package::pointerArithmeticFormsAnInvalidPointerQuery()) and
396-
exists(FatPointer start, int srcOffset, int sinkOffset, int length |
397+
exists(FatPointer start, int srcOffset, int sinkOffset |
397398
src.getNode() = start.getNode() and
398399
sink.getNode() = end.getBasePointerNode()
399400
|
400401
srcSinkLengthMap(start, end, srcOffset, sinkOffset, length) and
402+
totalOffset = srcOffset + sinkOffset and
401403
(
402-
srcOffset + sinkOffset < 0 or // Underflow detection
403-
srcOffset + sinkOffset > length // Overflow detection
404-
) and
405-
message = "srcOffset: " + srcOffset + ", sinkOffset: " + sinkOffset + ", length: " + length
404+
totalOffset < 0 or // Underflow detection
405+
totalOffset > length // Overflow detection
406+
)
406407
)
407-
select end, src, sink, message
408+
select end, src, sink,
409+
"This pointer accesses element at index " + totalOffset +
410+
" while the underlying object has length " + length + "."

0 commit comments

Comments
 (0)