@@ -15,33 +15,22 @@ import codingstandards.c.misra
1515import codingstandards.cpp.ReadErrorsAndEOF
1616import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
1717
18- //import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
1918class CtypeFunction extends Function {
2019 CtypeFunction ( ) { this .getADeclaration ( ) .getAFile ( ) .( HeaderFile ) .getBaseName ( ) = "ctype.h" }
2120}
2221
23- /* TODO Under construction */
2422from FunctionCall ctypeCall
2523where
2624 not isExcluded ( ctypeCall ,
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."
25+ StandardLibraryFunctionTypesPackage:: ctypeFunctionArgNotUnsignedCharOrEofQuery ( ) ) and
26+ not exists ( CtypeFunction ctype , Expr ctypeCallArgument |
27+ ctype = ctypeCall .getTarget ( ) and
28+ ctypeCallArgument = ctypeCall .getAnArgument ( ) .getExplicitlyConverted ( )
29+ |
30+ /* The argument's value should be in the EOF + `unsigned char` range. */
31+ - 1 <= lowerBound ( ctypeCallArgument ) and upperBound ( ctypeCallArgument ) <= 255
32+ ) and
33+ ctypeCall .getBasicBlock ( ) .isReachable ( )
34+ select ctypeCall ,
35+ "The <ctype.h> function " + ctypeCall + " accepts an argument " +
36+ ctypeCall .getAnArgument ( ) .toString ( ) + " that is not an unsigned char nor an EOF."
0 commit comments