Skip to content

Commit 9e60a8f

Browse files
committed
Use UseOfToOrIsChar from CharFunctions
1 parent 6d477c0 commit 9e60a8f

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,19 @@
1212

1313
import cpp
1414
import codingstandards.c.misra
15-
import codingstandards.cpp.ReadErrorsAndEOF
15+
import codingstandards.cpp.CharFunctions
1616
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
1717

18-
class CtypeFunction extends Function {
19-
CtypeFunction() { this.getADeclaration().getAFile().(HeaderFile).getBaseName() = "ctype.h" }
20-
}
21-
22-
from FunctionCall ctypeCall
18+
from UseOfToOrIsChar ctypeCall
2319
where
2420
not isExcluded(ctypeCall,
2521
StandardLibraryFunctionTypesPackage::ctypeFunctionArgNotUnsignedCharOrEofQuery()) and
26-
not exists(CtypeFunction ctype, Expr ctypeCallArgument |
27-
ctype = ctypeCall.getTarget() and
28-
ctypeCallArgument = ctypeCall.getAnArgument().getExplicitlyConverted()
22+
not exists(Expr ctypeCallArgument |
23+
ctypeCallArgument = ctypeCall.getConvertedArgument().getExplicitlyConverted()
2924
|
3025
/* The argument's value should be in the EOF + `unsigned char` range. */
3126
-1 <= lowerBound(ctypeCallArgument) and upperBound(ctypeCallArgument) <= 255
32-
) and
33-
/* Only report control flow that is feasible (to avoid <ctype.h> functions implemented as macro). */
34-
ctypeCall.getBasicBlock().isReachable()
27+
)
3528
select ctypeCall,
3629
"The <ctype.h> function " + ctypeCall + " accepts an argument " +
37-
ctypeCall.getAnArgument().toString() + " that is not an unsigned char nor an EOF."
30+
ctypeCall.getConvertedArgument().toString() + " that is not an unsigned char nor an EOF."

0 commit comments

Comments
 (0)