Skip to content

Commit ed16770

Browse files
committed
Rule 24.5.1 - improve structure/consistency of query
1 parent 52b97e6 commit ed16770

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

cpp/misra/src/rules/RULE-24-5-1/CharacterHandlingFunctionRestrictions.ql

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,25 @@ import codingstandards.cpp.BannedFunctions
2020
class BannedCharacterHandlingFunction extends Function {
2121
BannedCharacterHandlingFunction() {
2222
this.hasGlobalOrStdName([
23-
"isalnum", "isalpha", "isblank", "iscntrl", "isdigit", "isgraph", "islower", "isprint",
24-
"ispunct", "isspace", "isupper", "isxdigit", "tolower", "toupper",
25-
"iswalnum", "iswalpha", "iswblank", "iswcntrl", "iswctype", "iswdigit", "iswgraph",
26-
"iswlower", "iswprint", "iswpunct", "iswspace", "iswupper", "iswxdigit", "towctrans",
27-
"towlower", "towupper", "wctrans", "wctype"
28-
]) and
29-
not (
30-
this.hasGlobalOrStdName([
3123
"isalnum", "isalpha", "isblank", "iscntrl", "isdigit", "isgraph", "islower", "isprint",
32-
"ispunct", "isspace", "isupper", "isxdigit", "tolower", "toupper"
24+
"ispunct", "isspace", "isupper", "isxdigit", "tolower", "toupper", "iswalnum", "iswalpha",
25+
"iswblank", "iswcntrl", "iswctype", "iswdigit", "iswgraph", "iswlower", "iswprint",
26+
"iswpunct", "iswspace", "iswupper", "iswxdigit", "towctrans", "towlower", "towupper",
27+
"wctrans", "wctype"
3328
]) and
34-
this.getACallToThisFunction().(FunctionCall).getNumberOfArguments() = 2
35-
)
29+
// Exclude the functions which pass a reference to a std::locale as the second parameter
30+
not this.getParameter(1)
31+
.getType()
32+
.getUnspecifiedType()
33+
.(ReferenceType)
34+
.getBaseType()
35+
.(UserType)
36+
.hasQualifiedName("std", "locale")
3637
}
3738
}
3839

3940
from BannedFunctions<BannedCharacterHandlingFunction>::Use use
40-
where
41-
not isExcluded(use, BannedAPIsPackage::characterHandlingFunctionRestrictionsQuery())
42-
select use, use.getAction() + " banned character handling function '" + use.getFunctionName() + "' from <cctype> or <cwctype>."
41+
where not isExcluded(use, BannedAPIsPackage::characterHandlingFunctionRestrictionsQuery())
42+
select use,
43+
use.getAction() + " banned character handling function '" + use.getFunctionName() +
44+
"' from <cctype> or <cwctype>."

0 commit comments

Comments
 (0)