Skip to content

Commit 215a96c

Browse files
committed
Rule 21.10.1: Support other uses of va_list
1 parent 516ef74 commit 215a96c

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

cpp/misra/src/rules/RULE-21-10-1/NoVariadicFunctionMacros.ql

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import cpp
1616
import codingstandards.cpp.misra
17+
import codingstandards.cpp.types.Uses
1718

1819
class VaListType extends Type {
1920
VaListType() {
@@ -27,15 +28,24 @@ from Element element, string message
2728
where
2829
not isExcluded(element, BannedAPIsPackage::noVariadicFunctionMacrosQuery()) and
2930
(
30-
element.(Variable).getType() instanceof VaListType and
31+
element = getATypeUse(any(VaListType vlt)) and
3132
(
3233
if element instanceof Parameter
3334
then
3435
message =
3536
"Declaration of parameter '" + element.(Parameter).getName() + "' of type 'va_list'."
3637
else
37-
message =
38-
"Declaration of variable '" + element.(Variable).getName() + "' of type 'va_list'."
38+
if element instanceof Variable
39+
then
40+
message =
41+
"Declaration of variable '" + element.(Variable).getName() + "' of type 'va_list'."
42+
else
43+
if element instanceof TypedefType
44+
then
45+
message =
46+
"Declaration of typedef '" + element.(TypedefType).getName() +
47+
"' aliasing 'va_list' type."
48+
else message = "Use of 'va_list' type in an unsupported context."
3949
)
4050
or
4151
element instanceof BuiltInVarArgsStart and
@@ -49,9 +59,5 @@ where
4959
or
5060
element instanceof BuiltInVarArgCopy and
5161
message = "Call to 'va_copy'."
52-
or
53-
element.(TypedefType).getBaseType() instanceof VaListType and
54-
message =
55-
"Declaration of typedef '" + element.(TypedefType).getName() + "' aliasing 'va_list' type."
5662
)
5763
select element, message

cpp/misra/test/rules/RULE-21-10-1/NoVariadicFunctionMacros.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
| test.cpp:56:17:56:25 | SOME_TYPE | Declaration of typedef 'SOME_TYPE' aliasing 'va_list' type. |
2727
| test.cpp:58:17:58:18 | l1 | Declaration of variable 'l1' of type 'va_list'. |
2828
| test.cpp:59:13:59:14 | l2 | Declaration of variable 'l2' of type 'va_list'. |
29+
| test.cpp:65:12:65:13 | l1 | Declaration of variable 'l1' of type 'va_list'. |

cpp/misra/test/rules/RULE-21-10-1/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,10 @@ typedef va_list SOME_TYPE; // NON_COMPLIANT
5757
void test_va_list_alias() {
5858
va_list_alias l1; // NON_COMPLIANT
5959
SOME_TYPE l2; // NON_COMPLIANT
60+
}
61+
62+
// Note: use of va_list as a return type, or a cast, is not legal
63+
64+
void test_va_list() {
65+
va_list *l1; // NON_COMPLIANT - pointer to va_list
6066
}

0 commit comments

Comments
 (0)