Skip to content

Commit 4e5e05a

Browse files
committed
INT34-C: Improve alert message.
* Include uncertainty in the alert message (e.g. "may") * Report upper bound if relevant.
1 parent b79e1e8 commit 4e5e05a

File tree

2 files changed

+164
-163
lines changed

2 files changed

+164
-163
lines changed

c/cert/src/rules/INT34-C/ExprShiftedbyNegativeOrGreaterPrecisionOperand.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ int getPrecision(IntegralType type) {
5555
predicate isForbiddenShiftExpr(BitShiftExpr shift, string message) {
5656
(
5757
(
58-
getPrecision(shift.getLeftOperand().getFullyConverted().getUnderlyingType()) <=
58+
getPrecision(shift.getLeftOperand().getExplicitlyConverted().getUnderlyingType()) <=
5959
upperBound(shift.getRightOperand()) and
6060
message =
6161
"The operand " + shift.getLeftOperand() + " is shifted by an expression " +
62-
shift.getRightOperand() + " which is greater than or equal to in precision."
62+
shift.getRightOperand() + " whose upper bound (" + upperBound(shift.getRightOperand()) +
63+
") is greater than or equal to the precision."
6364
or
6465
lowerBound(shift.getRightOperand()) < 0 and
6566
message =
66-
"The operand " + shift.getLeftOperand() + " is shifted by a negative expression " +
67-
shift.getRightOperand() + "."
67+
"The operand " + shift.getLeftOperand() + " is shifted by an expression " +
68+
shift.getRightOperand() + " which may be negative."
6869
) and
6970
/*
7071
* Shift statement is not at a basic block where

0 commit comments

Comments
 (0)