Skip to content

Commit a9f2fbe

Browse files
committed
checkpoint
1 parent 4d55a70 commit a9f2fbe

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

c/misra/src/rules/RULE-21-13/CtypeFunctionArgNotUnsignedCharOrEof.ql

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,34 @@ import cpp
1414
import codingstandards.c.misra
1515
import codingstandards.cpp.ReadErrorsAndEOF
1616
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
17-
import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
1817

18+
//import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
1919
class CtypeFunction extends Function {
2020
CtypeFunction() { this.getADeclaration().getAFile().(HeaderFile).getBaseName() = "ctype.h" }
2121
}
2222

23+
/* TODO Under construction */
2324
from FunctionCall ctypeCall
2425
where
2526
not isExcluded(ctypeCall,
26-
StandardLibraryFunctionTypesPackage::ctypeFunctionArgNotUnsignedCharOrEofQuery()) and
27-
not exists(CtypeFunction ctype, UnsignedCharType unsignedChar |
28-
ctypeCall = ctype.getACallToThisFunction()
29-
|
30-
/* Case 1: The argument's value should be in the `unsigned char` range. */
31-
// Use `.getExplicitlyConverted` to consider inline argument casts.
32-
typeLowerBound(unsignedChar) <= lowerBound(ctypeCall.getAnArgument().getExplicitlyConverted()) and
33-
upperBound(ctypeCall.getAnArgument().getExplicitlyConverted()) <= typeUpperBound(unsignedChar)
34-
or
35-
/* Case 2: EOF flows to this argument without modifications. */
36-
exists(EOFInvocation eof |
37-
DataFlow::localFlow(DataFlow::exprNode(eof.getExpr()),
38-
DataFlow::exprNode(ctypeCall.getAnArgument()))
39-
)
40-
)
41-
select ctypeCall,
42-
"The <ctype.h> function " + ctypeCall + " accepts an argument " +
43-
ctypeCall.getAnArgument().toString() + " that is not an unsigned char nor an EOF."
27+
StandardLibraryFunctionTypesPackage::ctypeFunctionArgNotUnsignedCharOrEofQuery())
28+
// and
29+
// not exists(CtypeFunction ctype, Expr ctypeCallArgument |
30+
// ctype = ctypeCall.getTarget() and
31+
// ctypeCallArgument = ctypeCall.getAnArgument().getExplicitlyConverted()
32+
// |
33+
// /* Case 1: The argument's value should be in the `unsigned char` range. */
34+
// // Use `.getExplicitlyConverted` to consider inline argument casts.
35+
// -1 <= lowerBound(ctypeCallArgument) and
36+
// upperBound(ctypeCallArgument) <= 255
37+
// or
38+
// /* Case 2: EOF flows to this argument without modifications. */
39+
// exists(EOFInvocation eof |
40+
// DataFlow::localFlow(DataFlow::exprNode(eof.getExpr()), DataFlow::exprNode(ctypeCallArgument))
41+
// )
42+
// )
43+
select ctypeCall.getAnArgument(), lowerBound(ctypeCall.getAnArgument()),
44+
upperBound(ctypeCall.getAnArgument())
45+
// select ctypeCall,
46+
// "The <ctype.h> function " + ctypeCall + " accepts an argument " +
47+
// ctypeCall.getAnArgument().toString() + " that is not an unsigned char nor an EOF."

0 commit comments

Comments
 (0)