@@ -14,30 +14,34 @@ import cpp
1414import codingstandards.c.misra
1515import codingstandards.cpp.ReadErrorsAndEOF
1616import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
17- import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
1817
18+ //import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
1919class CtypeFunction extends Function {
2020 CtypeFunction ( ) { this .getADeclaration ( ) .getAFile ( ) .( HeaderFile ) .getBaseName ( ) = "ctype.h" }
2121}
2222
23+ /* TODO Under construction */
2324from FunctionCall ctypeCall
2425where
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