From dad044ed54cfba7fd6b0b6ffeb52061a1e4e2a29 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Tue, 31 Oct 2023 17:02:29 +0000 Subject: [PATCH 01/62] C++: Accept test changes after github/codeql/pull/14637. --- .../MissingConstructorCallForManuallyManagedObject.expected | 4 ++++ cpp/cert/test/rules/MEM53-CPP/test.cpp | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected b/cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected index 7225190e38..e06f6b9a63 100644 --- a/cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected +++ b/cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected @@ -2,6 +2,7 @@ WARNING: Module DataFlow has been deprecated and may be removed in future (/home WARNING: Module DataFlow has been deprecated and may be removed in future (/home/runner/work/semmle-code/semmle-code/codeql-coding-standards/cpp/cert/src/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.ql:25,38-46) WARNING: Module DataFlow has been deprecated and may be removed in future (/home/runner/work/semmle-code/semmle-code/codeql-coding-standards/cpp/cert/src/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.ql:25,65-73) edges +| test.cpp:65:21:65:34 | call to operator new | test.cpp:67:26:67:32 | call to realloc | nodes | test.cpp:16:26:16:31 | call to malloc | semmle.label | call to malloc | | test.cpp:17:38:17:43 | call to malloc | semmle.label | call to malloc | @@ -12,6 +13,8 @@ nodes | test.cpp:47:26:47:39 | call to operator new | semmle.label | call to operator new | | test.cpp:49:29:49:42 | call to operator new | semmle.label | call to operator new | | test.cpp:51:29:51:42 | call to operator new | semmle.label | call to operator new | +| test.cpp:65:21:65:34 | call to operator new | semmle.label | call to operator new | +| test.cpp:67:26:67:32 | call to realloc | semmle.label | call to realloc | subpaths #select | test.cpp:16:26:16:31 | call to malloc | test.cpp:16:26:16:31 | call to malloc | test.cpp:16:26:16:31 | call to malloc | Allocation to cast without constructor call | @@ -23,3 +26,4 @@ subpaths | test.cpp:47:26:47:39 | call to operator new | test.cpp:47:26:47:39 | call to operator new | test.cpp:47:26:47:39 | call to operator new | Allocation to cast without constructor call | | test.cpp:49:29:49:42 | call to operator new | test.cpp:49:29:49:42 | call to operator new | test.cpp:49:29:49:42 | call to operator new | Allocation to cast without constructor call | | test.cpp:51:29:51:42 | call to operator new | test.cpp:51:29:51:42 | call to operator new | test.cpp:51:29:51:42 | call to operator new | Allocation to cast without constructor call | +| test.cpp:67:26:67:32 | call to realloc | test.cpp:65:21:65:34 | call to operator new | test.cpp:67:26:67:32 | call to realloc | Allocation to cast without constructor call | diff --git a/cpp/cert/test/rules/MEM53-CPP/test.cpp b/cpp/cert/test/rules/MEM53-CPP/test.cpp index 12c6d1ee56..82c0953a60 100644 --- a/cpp/cert/test/rules/MEM53-CPP/test.cpp +++ b/cpp/cert/test/rules/MEM53-CPP/test.cpp @@ -63,6 +63,7 @@ void test_no_constructor_but_has_destructor() { void test_realloc() { void *goodAlloc = ::operator new(sizeof(ClassA)); - ClassA *a1 = new (goodAlloc) ClassA{1}; // COMPLIANT - ClassA *a2 = (ClassA *)realloc(goodAlloc, sizeof(ClassA) * 2); // COMPLIANT + ClassA *a1 = new (goodAlloc) ClassA{1}; // COMPLIANT + ClassA *a2 = (ClassA *)realloc( + goodAlloc, sizeof(ClassA) * 2); // COMPLIANT [FALSE_POSITIVE] } \ No newline at end of file From faf222e15365f1d86bf468912afb21491094829d Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Tue, 28 Nov 2023 17:00:26 +0100 Subject: [PATCH 02/62] Use new `isPrototyped` predicate in RULE-8-2 From CodeQL 2.15.4 onwards, parameters declared in a declaration list will have a location. --- .../rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql b/c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql index e46085750d..583bf257aa 100644 --- a/c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql +++ b/c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql @@ -48,11 +48,9 @@ where msg = "Function " + f + " does not specify void for no parameters present." or //parameters declared in declaration list (not in function signature) - //have placeholder file location associated only - exists(Parameter p | - p.getFunction() = f and - not p.getFile() = f.getFile() and - msg = "Function " + f + " declares parameter in unsupported declaration list." - ) + //have no prototype + not f.isPrototyped() and + not hasZeroParamDecl(f) and + msg = "Function " + f + " declares parameter in unsupported declaration list." ) select f, msg From 95d048ad923e60a359ec264cd2285b7025400b4a Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Tue, 28 Nov 2023 16:14:58 +0000 Subject: [PATCH 03/62] C++: Disable the workaround for bitwise operations since the underlying bug has been fixed. --- cpp/common/src/codingstandards/cpp/Bitwise.qll | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/cpp/common/src/codingstandards/cpp/Bitwise.qll b/cpp/common/src/codingstandards/cpp/Bitwise.qll index 0e19cae29d..871587b4ea 100644 --- a/cpp/common/src/codingstandards/cpp/Bitwise.qll +++ b/cpp/common/src/codingstandards/cpp/Bitwise.qll @@ -5,16 +5,6 @@ private import cpp as cpp module Bitwise { - /** - * A binary bitwise assign operation, excluding += and -= on pointers, which seem to be erroneously - * included. - */ - class AssignBitwiseOperation extends cpp::AssignBitwiseOperation { - AssignBitwiseOperation() { - // exclude += and -= on pointers, which seem to be erroneously included - // in the database schema - not this instanceof cpp::AssignPointerAddExpr and - not this instanceof cpp::AssignPointerSubExpr - } - } + /** A binary bitwise assign operation. */ + class AssignBitwiseOperation extends cpp::AssignBitwiseOperation { } } From f553ba0d5fd3d8e02d069e4cf283e4dce85a278d Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 29 Nov 2023 10:08:44 +0000 Subject: [PATCH 04/62] Completely rip out the Bitwise library. --- .../OperandsOfAnInappropriateEssentialType.ql | 3 +-- ...twiseOperatorOperandsHaveDifferentUnderlyingType.ql | 3 +-- .../M5-0-21/BitwiseOperatorAppliedToSignedTypes.ql | 3 +-- .../M5-8-1/RightBitShiftOperandIsNegativeOrTooWide.ql | 3 +-- cpp/common/src/codingstandards/cpp/Bitwise.qll | 10 ---------- 5 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 cpp/common/src/codingstandards/cpp/Bitwise.qll diff --git a/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql b/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql index 6fdde80119..005b7c6cf5 100644 --- a/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql +++ b/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql @@ -14,7 +14,6 @@ import cpp import codingstandards.c.misra import codingstandards.c.misra.EssentialTypes -import codingstandards.cpp.Bitwise /** * Holds if the operator `operator` has an operand `child` that is of an inappropriate essential type @@ -178,7 +177,7 @@ predicate isInappropriateEssentialType( child = [ operator.(BinaryBitwiseOperation).getAnOperand(), - operator.(Bitwise::AssignBitwiseOperation).getAnOperand() + operator.(AssignBitwiseOperation).getAnOperand() ] and not operator instanceof LShiftExpr and not operator instanceof RShiftExpr and diff --git a/cpp/autosar/src/rules/M5-0-20/BitwiseOperatorOperandsHaveDifferentUnderlyingType.ql b/cpp/autosar/src/rules/M5-0-20/BitwiseOperatorOperandsHaveDifferentUnderlyingType.ql index 9e85a15e50..6d0554bf11 100644 --- a/cpp/autosar/src/rules/M5-0-20/BitwiseOperatorOperandsHaveDifferentUnderlyingType.ql +++ b/cpp/autosar/src/rules/M5-0-20/BitwiseOperatorOperandsHaveDifferentUnderlyingType.ql @@ -16,7 +16,6 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Bitwise import codingstandards.cpp.Conversion predicate isBinaryBitwiseOperation(Operation o, VariableAccess l, VariableAccess r) { @@ -24,7 +23,7 @@ predicate isBinaryBitwiseOperation(Operation o, VariableAccess l, VariableAccess l = bbo.getLeftOperand() and r = bbo.getRightOperand() ) or - exists(Bitwise::AssignBitwiseOperation abo | abo = o | + exists(AssignBitwiseOperation abo | abo = o | l = abo.getLValue() and r = abo.getRValue() ) diff --git a/cpp/autosar/src/rules/M5-0-21/BitwiseOperatorAppliedToSignedTypes.ql b/cpp/autosar/src/rules/M5-0-21/BitwiseOperatorAppliedToSignedTypes.ql index d000155189..02bb5314cd 100644 --- a/cpp/autosar/src/rules/M5-0-21/BitwiseOperatorAppliedToSignedTypes.ql +++ b/cpp/autosar/src/rules/M5-0-21/BitwiseOperatorAppliedToSignedTypes.ql @@ -17,7 +17,6 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Bitwise from Operation o, VariableAccess va where @@ -25,7 +24,7 @@ where ( o instanceof UnaryBitwiseOperation or o instanceof BinaryBitwiseOperation or - o instanceof Bitwise::AssignBitwiseOperation + o instanceof AssignBitwiseOperation ) and o.getAnOperand() = va and va.getTarget().getUnderlyingType().(IntegralType).isSigned() diff --git a/cpp/autosar/src/rules/M5-8-1/RightBitShiftOperandIsNegativeOrTooWide.ql b/cpp/autosar/src/rules/M5-8-1/RightBitShiftOperandIsNegativeOrTooWide.ql index 38da7115f3..b94d76fd94 100644 --- a/cpp/autosar/src/rules/M5-8-1/RightBitShiftOperandIsNegativeOrTooWide.ql +++ b/cpp/autosar/src/rules/M5-8-1/RightBitShiftOperandIsNegativeOrTooWide.ql @@ -17,7 +17,6 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Bitwise class ShiftOperation extends Operation { Expr leftOperand; @@ -34,7 +33,7 @@ class ShiftOperation extends Operation { rightOperand = o.getRightOperand() ) or - exists(Bitwise::AssignBitwiseOperation o | this = o | + exists(AssignBitwiseOperation o | this = o | ( o instanceof AssignLShiftExpr or diff --git a/cpp/common/src/codingstandards/cpp/Bitwise.qll b/cpp/common/src/codingstandards/cpp/Bitwise.qll deleted file mode 100644 index 871587b4ea..0000000000 --- a/cpp/common/src/codingstandards/cpp/Bitwise.qll +++ /dev/null @@ -1,10 +0,0 @@ -/** - * A library for addressing issues in bitwise operator modelling in our database schema. - */ - -private import cpp as cpp - -module Bitwise { - /** A binary bitwise assign operation. */ - class AssignBitwiseOperation extends cpp::AssignBitwiseOperation { } -} From a6409e47d384c44019d780bb6ca683b5fed6ec8f Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Wed, 18 Sep 2024 22:52:51 +0100 Subject: [PATCH 05/62] Rule 1.2: Report specific extensions used Distinguish between the different types of extensions. --- c/common/src/codingstandards/c/Extensions.qll | 89 ++++++++++++--- .../LanguageExtensionsShouldNotBeUsed.ql | 2 +- ...LanguageExtensionsShouldNotBeUsed.expected | 102 +++++++++--------- 3 files changed, 129 insertions(+), 64 deletions(-) diff --git a/c/common/src/codingstandards/c/Extensions.qll b/c/common/src/codingstandards/c/Extensions.qll index 018359586e..a30f1ec45b 100644 --- a/c/common/src/codingstandards/c/Extensions.qll +++ b/c/common/src/codingstandards/c/Extensions.qll @@ -4,21 +4,28 @@ import codingstandards.cpp.Extensions /** * Common base class for modeling compiler extensions. */ -abstract class CCompilerExtension extends CompilerExtension { } +abstract class CCompilerExtension extends CompilerExtension { + abstract string getMessage(); +} // Reference: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#Other-Builtins abstract class CConditionalDefineExtension extends CCompilerExtension, PreprocessorIfdef { + string feature; + CConditionalDefineExtension() { - exists(toString().indexOf("__has_builtin")) or - exists(toString().indexOf("__has_constexpr_builtin")) or - exists(toString().indexOf("__has_feature")) or - exists(toString().indexOf("__has_extension")) or - exists(toString().indexOf("__has_attribute")) or - exists(toString().indexOf("__has_declspec_attribute")) or - exists(toString().indexOf("__is_identifier")) or - exists(toString().indexOf("__has_include")) or - exists(toString().indexOf("__has_include_next")) or - exists(toString().indexOf("__has_warning")) + feature = + [ + "__has_builtin", "__has_constexpr_builtin", "__has_feature", "__has_extension", + "__has_attribute", "__has_declspec_attribute", "__is_identifier", "__has_include", + "__has_include_next", "__has_warning" + ] and + exists(toString().indexOf(feature)) + } + + override string getMessage() { + result = + "Call to builtin function '" + feature + + "' is a compiler extension and is not portable to other compilers." } } @@ -31,6 +38,12 @@ class CMacroBasedExtension extends CCompilerExtension, Macro { "__clang_version__", "__clang_literal_encoding__", "__clang_wide_literal_encoding__" ] } + + override string getMessage() { + result = + "Use of builtin macro '" + getBody() + + "' is a compiler extension and is not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html#Variable-Attributes @@ -41,6 +54,12 @@ class CAttributeExtension extends CCompilerExtension, Attribute { "fallthrough", "read_only", "alias" ] } + + override string getMessage() { + result = + "Use of attribute '" + getName() + + "' is a compiler extension and is not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html#g_t_005f_005fsync-Builtins @@ -61,21 +80,41 @@ class CFunctionExtension extends CCompilerExtension, FunctionCall { // the built-in extensions getTarget().getName().indexOf("__builtin_") = 0 } + + override string getMessage() { + result = + "Call to builtin function '" + getTarget().getName() + + "' is a compiler extension and is not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/Alignment.html#Alignment class CFunctionLikeExtension extends CCompilerExtension, AlignofExprOperator { CFunctionLikeExtension() { exists(getValueText().indexOf("__alignof__")) } + + override string getMessage() { + result = "'__alignof__' is a compiler extension and is not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs -class CStmtExprExtension extends CCompilerExtension, StmtExpr { } +class CStmtExprExtension extends CCompilerExtension, StmtExpr { + override string getMessage() { + result = + "Statement expressions are a compiler extension and are not portable to other compilers." + } +} // Use of ternary like the following: `int a = 0 ?: 0;` where the // one of the branches is omitted // Reference: https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html#Conditionals class CTerseTernaryExtension extends CCompilerExtension, ConditionalExpr { CTerseTernaryExtension() { getCondition() = getElse() or getCondition() = getThen() } + + override string getMessage() { + result = + "Ternaries with omitted middle operands are a compiler extension and is not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html#g_t_005f_005fint128 @@ -87,25 +126,46 @@ class CRealTypeExtensionExtension extends CCompilerExtension, DeclarationEntry { getType() instanceof Decimal64Type or getType() instanceof Float128Type } + + override string getMessage() { + result = "Decimal floats are a compiler extension and are not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html#g_t_005f_005fint128 class CIntegerTypeExtension extends CCompilerExtension, DeclarationEntry { CIntegerTypeExtension() { getType() instanceof Int128Type } + + override string getMessage() { + result = "128-bit integers are a compiler extension and are not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/Long-Long.html#Long-Long class CLongLongType extends CCompilerExtension, DeclarationEntry { CLongLongType() { getType() instanceof LongLongType } + + override string getMessage() { + result = + "Double-Word integers are a compiler extension and are not portable to other compilers." + } } class CZeroLengthArraysExtension extends CCompilerExtension, DeclarationEntry { CZeroLengthArraysExtension() { getType().(ArrayType).getArraySize() = 0 } + + override string getMessage() { + result = "Zero length arrays are a compiler extension and are not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/Empty-Structures.html#Empty-Structures class CEmptyStructExtension extends CCompilerExtension, Struct { CEmptyStructExtension() { not exists(getAMember(_)) } + + override string getMessage() { + result = "Empty structures are a compiler extension and are not portable to other compilers." + } } // Reference: https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html#Variable-Length @@ -114,4 +174,9 @@ class CVariableLengthArraysExtension extends CCompilerExtension, DeclarationEntr getType() instanceof ArrayType and not getType().(ArrayType).hasArraySize() } + + override string getMessage() { + result = + "Variable length arrays are a compiler extension and are not portable to other compilers." + } } diff --git a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql index f38e41a1b6..00a364a87e 100644 --- a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql @@ -17,4 +17,4 @@ import codingstandards.c.Extensions from CCompilerExtension e where not isExcluded(e, Language3Package::languageExtensionsShouldNotBeUsedQuery()) -select e, "Is a compiler extension and is not portable to other compilers." +select e, e.getMessage() diff --git a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected index f9f034c980..d13141d7ac 100644 --- a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected +++ b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected @@ -1,51 +1,51 @@ -| test.c:34:1:34:23 | #define A __BASE_FILE__ | Is a compiler extension and is not portable to other compilers. | -| test.c:35:1:35:23 | #define B __FILE_NAME__ | Is a compiler extension and is not portable to other compilers. | -| test.c:36:1:36:21 | #define C __COUNTER__ | Is a compiler extension and is not portable to other compilers. | -| test.c:37:1:37:27 | #define D __INCLUDE_LEVEL__ | Is a compiler extension and is not portable to other compilers. | -| test.c:39:1:39:19 | #define F __clang__ | Is a compiler extension and is not portable to other compilers. | -| test.c:40:1:40:25 | #define G __clang_major__ | Is a compiler extension and is not portable to other compilers. | -| test.c:41:1:41:25 | #define H __clang_minor__ | Is a compiler extension and is not portable to other compilers. | -| test.c:42:1:42:30 | #define I __clang_patchlevel__ | Is a compiler extension and is not portable to other compilers. | -| test.c:43:1:43:27 | #define J __clang_version__ | Is a compiler extension and is not portable to other compilers. | -| test.c:44:1:44:36 | #define K __clang_literal_encoding__ | Is a compiler extension and is not portable to other compilers. | -| test.c:45:1:45:41 | #define L __clang_wide_literal_encoding__ | Is a compiler extension and is not portable to other compilers. | -| test.c:53:33:53:43 | vector_size | Is a compiler extension and is not portable to other compilers. | -| test.c:54:33:54:47 | vector_size | Is a compiler extension and is not portable to other compilers. | -| test.c:55:37:55:51 | ext_vector_type | Is a compiler extension and is not portable to other compilers. | -| test.c:56:37:56:51 | ext_vector_type | Is a compiler extension and is not portable to other compilers. | -| test.c:61:3:69:4 | (statement expression) | Is a compiler extension and is not portable to other compilers. | -| test.c:96:3:96:18 | call to __builtin_setjmp | Is a compiler extension and is not portable to other compilers. | -| test.c:97:3:97:19 | call to __builtin_longjmp | Is a compiler extension and is not portable to other compilers. | -| test.c:113:11:113:16 | ... ? ... : ... | Is a compiler extension and is not portable to other compilers. | -| test.c:124:12:124:12 | definition of a | Is a compiler extension and is not portable to other compilers. | -| test.c:128:17:128:17 | definition of a | Is a compiler extension and is not portable to other compilers. | -| test.c:165:8:165:15 | definition of contents | Is a compiler extension and is not portable to other compilers. | -| test.c:182:8:182:11 | gf19 | Is a compiler extension and is not portable to other compilers. | -| test.c:214:33:214:35 | declaration of out | Is a compiler extension and is not portable to other compilers. | -| test.c:215:25:215:26 | declaration of in | Is a compiler extension and is not portable to other compilers. | -| test.c:268:16:268:21 | access | Is a compiler extension and is not portable to other compilers. | -| test.c:271:27:271:31 | alias | Is a compiler extension and is not portable to other compilers. | -| test.c:274:23:274:29 | aligned | Is a compiler extension and is not portable to other compilers. | -| test.c:285:25:285:34 | deprecated | Is a compiler extension and is not portable to other compilers. | -| test.c:297:20:297:30 | fallthrough | Is a compiler extension and is not portable to other compilers. | -| test.c:321:3:321:22 | alignof() | Is a compiler extension and is not portable to other compilers. | -| test.c:340:3:340:31 | call to __builtin_extract_return_addr | Is a compiler extension and is not portable to other compilers. | -| test.c:341:3:341:28 | call to __builtin_frob_return_addr | Is a compiler extension and is not portable to other compilers. | -| test.c:342:3:342:25 | call to __builtin_frame_address | Is a compiler extension and is not portable to other compilers. | -| test.c:363:3:363:22 | call to __sync_fetch_and_add_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:364:3:364:22 | call to __sync_fetch_and_sub_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:365:3:365:21 | call to __sync_fetch_and_or_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:366:3:366:22 | call to __sync_fetch_and_and_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:367:3:367:22 | call to __sync_fetch_and_xor_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:368:3:368:23 | call to __sync_fetch_and_nand_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:369:3:369:22 | call to __sync_add_and_fetch_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:370:3:370:22 | call to __sync_sub_and_fetch_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:371:3:371:21 | call to __sync_or_and_fetch_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:372:3:372:22 | call to __sync_and_and_fetch_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:373:3:373:22 | call to __sync_xor_and_fetch_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:374:3:374:23 | call to __sync_nand_and_fetch_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:376:3:376:30 | call to __sync_bool_compare_and_swap_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:377:3:377:29 | call to __sync_val_compare_and_swap_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:378:3:378:26 | call to __sync_lock_test_and_set_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:379:3:379:21 | call to __sync_lock_release_4 | Is a compiler extension and is not portable to other compilers. | -| test.c:407:3:407:18 | call to __builtin_alloca | Is a compiler extension and is not portable to other compilers. | +| test.c:34:1:34:23 | #define A __BASE_FILE__ | Use of builtin macro '__BASE_FILE__' is a compiler extension and is not portable to other compilers. | +| test.c:35:1:35:23 | #define B __FILE_NAME__ | Use of builtin macro '__FILE_NAME__' is a compiler extension and is not portable to other compilers. | +| test.c:36:1:36:21 | #define C __COUNTER__ | Use of builtin macro '__COUNTER__' is a compiler extension and is not portable to other compilers. | +| test.c:37:1:37:27 | #define D __INCLUDE_LEVEL__ | Use of builtin macro '__INCLUDE_LEVEL__' is a compiler extension and is not portable to other compilers. | +| test.c:39:1:39:19 | #define F __clang__ | Use of builtin macro '__clang__' is a compiler extension and is not portable to other compilers. | +| test.c:40:1:40:25 | #define G __clang_major__ | Use of builtin macro '__clang_major__' is a compiler extension and is not portable to other compilers. | +| test.c:41:1:41:25 | #define H __clang_minor__ | Use of builtin macro '__clang_minor__' is a compiler extension and is not portable to other compilers. | +| test.c:42:1:42:30 | #define I __clang_patchlevel__ | Use of builtin macro '__clang_patchlevel__' is a compiler extension and is not portable to other compilers. | +| test.c:43:1:43:27 | #define J __clang_version__ | Use of builtin macro '__clang_version__' is a compiler extension and is not portable to other compilers. | +| test.c:44:1:44:36 | #define K __clang_literal_encoding__ | Use of builtin macro '__clang_literal_encoding__' is a compiler extension and is not portable to other compilers. | +| test.c:45:1:45:41 | #define L __clang_wide_literal_encoding__ | Use of builtin macro '__clang_wide_literal_encoding__' is a compiler extension and is not portable to other compilers. | +| test.c:53:33:53:43 | vector_size | Use of attribute 'vector_size' is a compiler extension and is not portable to other compilers. | +| test.c:54:33:54:47 | vector_size | Use of attribute 'vector_size' is a compiler extension and is not portable to other compilers. | +| test.c:55:37:55:51 | ext_vector_type | Use of attribute 'ext_vector_type' is a compiler extension and is not portable to other compilers. | +| test.c:56:37:56:51 | ext_vector_type | Use of attribute 'ext_vector_type' is a compiler extension and is not portable to other compilers. | +| test.c:61:3:69:4 | (statement expression) | Statement expressions are a compiler extension and are not portable to other compilers. | +| test.c:96:3:96:18 | call to __builtin_setjmp | Call to builtin function '__builtin_setjmp' is a compiler extension and is not portable to other compilers. | +| test.c:97:3:97:19 | call to __builtin_longjmp | Call to builtin function '__builtin_longjmp' is a compiler extension and is not portable to other compilers. | +| test.c:113:11:113:16 | ... ? ... : ... | Ternaries with omitted middle operands are a compiler extension and is not portable to other compilers. | +| test.c:124:12:124:12 | definition of a | 128-bit integers are a compiler extension and are not portable to other compilers. | +| test.c:128:17:128:17 | definition of a | Double-Word integers are a compiler extension and are not portable to other compilers. | +| test.c:165:8:165:15 | definition of contents | Zero length arrays are a compiler extension and are not portable to other compilers. | +| test.c:182:8:182:11 | gf19 | Empty structures are a compiler extension and are not portable to other compilers. | +| test.c:214:33:214:35 | declaration of out | Variable length arrays are a compiler extension and are not portable to other compilers. | +| test.c:215:25:215:26 | declaration of in | Variable length arrays are a compiler extension and are not portable to other compilers. | +| test.c:268:16:268:21 | access | Use of attribute 'access' is a compiler extension and is not portable to other compilers. | +| test.c:271:27:271:31 | alias | Use of attribute 'alias' is a compiler extension and is not portable to other compilers. | +| test.c:274:23:274:29 | aligned | Use of attribute 'aligned' is a compiler extension and is not portable to other compilers. | +| test.c:285:25:285:34 | deprecated | Use of attribute 'deprecated' is a compiler extension and is not portable to other compilers. | +| test.c:297:20:297:30 | fallthrough | Use of attribute 'fallthrough' is a compiler extension and is not portable to other compilers. | +| test.c:321:3:321:22 | alignof() | '__alignof__' is a compiler extension and is not portable to other compilers. | +| test.c:340:3:340:31 | call to __builtin_extract_return_addr | Call to builtin function '__builtin_extract_return_addr' is a compiler extension and is not portable to other compilers. | +| test.c:341:3:341:28 | call to __builtin_frob_return_addr | Call to builtin function '__builtin_frob_return_addr' is a compiler extension and is not portable to other compilers. | +| test.c:342:3:342:25 | call to __builtin_frame_address | Call to builtin function '__builtin_frame_address' is a compiler extension and is not portable to other compilers. | +| test.c:363:3:363:22 | call to __sync_fetch_and_add_4 | Call to builtin function '__sync_fetch_and_add_4' is a compiler extension and is not portable to other compilers. | +| test.c:364:3:364:22 | call to __sync_fetch_and_sub_4 | Call to builtin function '__sync_fetch_and_sub_4' is a compiler extension and is not portable to other compilers. | +| test.c:365:3:365:21 | call to __sync_fetch_and_or_4 | Call to builtin function '__sync_fetch_and_or_4' is a compiler extension and is not portable to other compilers. | +| test.c:366:3:366:22 | call to __sync_fetch_and_and_4 | Call to builtin function '__sync_fetch_and_and_4' is a compiler extension and is not portable to other compilers. | +| test.c:367:3:367:22 | call to __sync_fetch_and_xor_4 | Call to builtin function '__sync_fetch_and_xor_4' is a compiler extension and is not portable to other compilers. | +| test.c:368:3:368:23 | call to __sync_fetch_and_nand_4 | Call to builtin function '__sync_fetch_and_nand_4' is a compiler extension and is not portable to other compilers. | +| test.c:369:3:369:22 | call to __sync_add_and_fetch_4 | Call to builtin function '__sync_add_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:370:3:370:22 | call to __sync_sub_and_fetch_4 | Call to builtin function '__sync_sub_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:371:3:371:21 | call to __sync_or_and_fetch_4 | Call to builtin function '__sync_or_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:372:3:372:22 | call to __sync_and_and_fetch_4 | Call to builtin function '__sync_and_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:373:3:373:22 | call to __sync_xor_and_fetch_4 | Call to builtin function '__sync_xor_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:374:3:374:23 | call to __sync_nand_and_fetch_4 | Call to builtin function '__sync_nand_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:376:3:376:30 | call to __sync_bool_compare_and_swap_4 | Call to builtin function '__sync_bool_compare_and_swap_4' is a compiler extension and is not portable to other compilers. | +| test.c:377:3:377:29 | call to __sync_val_compare_and_swap_4 | Call to builtin function '__sync_val_compare_and_swap_4' is a compiler extension and is not portable to other compilers. | +| test.c:378:3:378:26 | call to __sync_lock_test_and_set_4 | Call to builtin function '__sync_lock_test_and_set_4' is a compiler extension and is not portable to other compilers. | +| test.c:379:3:379:21 | call to __sync_lock_release_4 | Call to builtin function '__sync_lock_release_4' is a compiler extension and is not portable to other compilers. | +| test.c:407:3:407:18 | call to __builtin_alloca | Call to builtin function '__builtin_alloca' is a compiler extension and is not portable to other compilers. | From 9605d7954cc7d04a61bbf28d0ecdb35ae0aff0c6 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Wed, 18 Sep 2024 23:13:39 +0100 Subject: [PATCH 06/62] Rule 1.2: Correct detection of variable length arrays --- c/common/src/codingstandards/c/Extensions.qll | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/c/common/src/codingstandards/c/Extensions.qll b/c/common/src/codingstandards/c/Extensions.qll index a30f1ec45b..4f16a1f09a 100644 --- a/c/common/src/codingstandards/c/Extensions.qll +++ b/c/common/src/codingstandards/c/Extensions.qll @@ -169,10 +169,16 @@ class CEmptyStructExtension extends CCompilerExtension, Struct { } // Reference: https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html#Variable-Length -class CVariableLengthArraysExtension extends CCompilerExtension, DeclarationEntry { +class CVariableLengthArraysExtension extends CCompilerExtension, Field { CVariableLengthArraysExtension() { getType() instanceof ArrayType and - not getType().(ArrayType).hasArraySize() + not getType().(ArrayType).hasArraySize() and + // Not the final member of the struct, which is allowed to be variably sized + not exists(int lastIndex, Class declaringStruct | + declaringStruct = getDeclaringType() and + lastIndex = count(declaringStruct.getACanonicalMember()) - 1 and + this = declaringStruct.getCanonicalMember(lastIndex) + ) } override string getMessage() { From 9139b8e21cb741cc56355ae7a19c68e04e572d58 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 19 Sep 2024 10:00:05 +0100 Subject: [PATCH 07/62] Rule 1.2: Fix test for variable length arrays Only variable length struct fields are a gcc extension. --- ...LanguageExtensionsShouldNotBeUsed.expected | 55 +++++++++---------- c/misra/test/rules/RULE-1-2/test.c | 14 ++--- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected index d13141d7ac..b82fa2bbc5 100644 --- a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected +++ b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected @@ -21,31 +21,30 @@ | test.c:128:17:128:17 | definition of a | Double-Word integers are a compiler extension and are not portable to other compilers. | | test.c:165:8:165:15 | definition of contents | Zero length arrays are a compiler extension and are not portable to other compilers. | | test.c:182:8:182:11 | gf19 | Empty structures are a compiler extension and are not portable to other compilers. | -| test.c:214:33:214:35 | declaration of out | Variable length arrays are a compiler extension and are not portable to other compilers. | -| test.c:215:25:215:26 | declaration of in | Variable length arrays are a compiler extension and are not portable to other compilers. | -| test.c:268:16:268:21 | access | Use of attribute 'access' is a compiler extension and is not portable to other compilers. | -| test.c:271:27:271:31 | alias | Use of attribute 'alias' is a compiler extension and is not portable to other compilers. | -| test.c:274:23:274:29 | aligned | Use of attribute 'aligned' is a compiler extension and is not portable to other compilers. | -| test.c:285:25:285:34 | deprecated | Use of attribute 'deprecated' is a compiler extension and is not portable to other compilers. | -| test.c:297:20:297:30 | fallthrough | Use of attribute 'fallthrough' is a compiler extension and is not portable to other compilers. | -| test.c:321:3:321:22 | alignof() | '__alignof__' is a compiler extension and is not portable to other compilers. | -| test.c:340:3:340:31 | call to __builtin_extract_return_addr | Call to builtin function '__builtin_extract_return_addr' is a compiler extension and is not portable to other compilers. | -| test.c:341:3:341:28 | call to __builtin_frob_return_addr | Call to builtin function '__builtin_frob_return_addr' is a compiler extension and is not portable to other compilers. | -| test.c:342:3:342:25 | call to __builtin_frame_address | Call to builtin function '__builtin_frame_address' is a compiler extension and is not portable to other compilers. | -| test.c:363:3:363:22 | call to __sync_fetch_and_add_4 | Call to builtin function '__sync_fetch_and_add_4' is a compiler extension and is not portable to other compilers. | -| test.c:364:3:364:22 | call to __sync_fetch_and_sub_4 | Call to builtin function '__sync_fetch_and_sub_4' is a compiler extension and is not portable to other compilers. | -| test.c:365:3:365:21 | call to __sync_fetch_and_or_4 | Call to builtin function '__sync_fetch_and_or_4' is a compiler extension and is not portable to other compilers. | -| test.c:366:3:366:22 | call to __sync_fetch_and_and_4 | Call to builtin function '__sync_fetch_and_and_4' is a compiler extension and is not portable to other compilers. | -| test.c:367:3:367:22 | call to __sync_fetch_and_xor_4 | Call to builtin function '__sync_fetch_and_xor_4' is a compiler extension and is not portable to other compilers. | -| test.c:368:3:368:23 | call to __sync_fetch_and_nand_4 | Call to builtin function '__sync_fetch_and_nand_4' is a compiler extension and is not portable to other compilers. | -| test.c:369:3:369:22 | call to __sync_add_and_fetch_4 | Call to builtin function '__sync_add_and_fetch_4' is a compiler extension and is not portable to other compilers. | -| test.c:370:3:370:22 | call to __sync_sub_and_fetch_4 | Call to builtin function '__sync_sub_and_fetch_4' is a compiler extension and is not portable to other compilers. | -| test.c:371:3:371:21 | call to __sync_or_and_fetch_4 | Call to builtin function '__sync_or_and_fetch_4' is a compiler extension and is not portable to other compilers. | -| test.c:372:3:372:22 | call to __sync_and_and_fetch_4 | Call to builtin function '__sync_and_and_fetch_4' is a compiler extension and is not portable to other compilers. | -| test.c:373:3:373:22 | call to __sync_xor_and_fetch_4 | Call to builtin function '__sync_xor_and_fetch_4' is a compiler extension and is not portable to other compilers. | -| test.c:374:3:374:23 | call to __sync_nand_and_fetch_4 | Call to builtin function '__sync_nand_and_fetch_4' is a compiler extension and is not portable to other compilers. | -| test.c:376:3:376:30 | call to __sync_bool_compare_and_swap_4 | Call to builtin function '__sync_bool_compare_and_swap_4' is a compiler extension and is not portable to other compilers. | -| test.c:377:3:377:29 | call to __sync_val_compare_and_swap_4 | Call to builtin function '__sync_val_compare_and_swap_4' is a compiler extension and is not portable to other compilers. | -| test.c:378:3:378:26 | call to __sync_lock_test_and_set_4 | Call to builtin function '__sync_lock_test_and_set_4' is a compiler extension and is not portable to other compilers. | -| test.c:379:3:379:21 | call to __sync_lock_release_4 | Call to builtin function '__sync_lock_release_4' is a compiler extension and is not portable to other compilers. | -| test.c:407:3:407:18 | call to __builtin_alloca | Call to builtin function '__builtin_alloca' is a compiler extension and is not portable to other compilers. | +| test.c:216:9:216:10 | definition of x1 | Zero length arrays are a compiler extension and are not portable to other compilers. | +| test.c:266:16:266:21 | access | Use of attribute 'access' is a compiler extension and is not portable to other compilers. | +| test.c:270:5:270:9 | alias | Use of attribute 'alias' is a compiler extension and is not portable to other compilers. | +| test.c:272:23:272:29 | aligned | Use of attribute 'aligned' is a compiler extension and is not portable to other compilers. | +| test.c:283:25:283:34 | deprecated | Use of attribute 'deprecated' is a compiler extension and is not portable to other compilers. | +| test.c:295:20:295:30 | fallthrough | Use of attribute 'fallthrough' is a compiler extension and is not portable to other compilers. | +| test.c:319:3:319:22 | alignof() | '__alignof__' is a compiler extension and is not portable to other compilers. | +| test.c:338:3:338:31 | call to __builtin_extract_return_addr | Call to builtin function '__builtin_extract_return_addr' is a compiler extension and is not portable to other compilers. | +| test.c:339:3:339:28 | call to __builtin_frob_return_addr | Call to builtin function '__builtin_frob_return_addr' is a compiler extension and is not portable to other compilers. | +| test.c:340:3:340:25 | call to __builtin_frame_address | Call to builtin function '__builtin_frame_address' is a compiler extension and is not portable to other compilers. | +| test.c:361:3:361:22 | call to __sync_fetch_and_add_4 | Call to builtin function '__sync_fetch_and_add_4' is a compiler extension and is not portable to other compilers. | +| test.c:362:3:362:22 | call to __sync_fetch_and_sub_4 | Call to builtin function '__sync_fetch_and_sub_4' is a compiler extension and is not portable to other compilers. | +| test.c:363:3:363:21 | call to __sync_fetch_and_or_4 | Call to builtin function '__sync_fetch_and_or_4' is a compiler extension and is not portable to other compilers. | +| test.c:364:3:364:22 | call to __sync_fetch_and_and_4 | Call to builtin function '__sync_fetch_and_and_4' is a compiler extension and is not portable to other compilers. | +| test.c:365:3:365:22 | call to __sync_fetch_and_xor_4 | Call to builtin function '__sync_fetch_and_xor_4' is a compiler extension and is not portable to other compilers. | +| test.c:366:3:366:23 | call to __sync_fetch_and_nand_4 | Call to builtin function '__sync_fetch_and_nand_4' is a compiler extension and is not portable to other compilers. | +| test.c:367:3:367:22 | call to __sync_add_and_fetch_4 | Call to builtin function '__sync_add_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:368:3:368:22 | call to __sync_sub_and_fetch_4 | Call to builtin function '__sync_sub_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:369:3:369:21 | call to __sync_or_and_fetch_4 | Call to builtin function '__sync_or_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:370:3:370:22 | call to __sync_and_and_fetch_4 | Call to builtin function '__sync_and_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:371:3:371:22 | call to __sync_xor_and_fetch_4 | Call to builtin function '__sync_xor_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:372:3:372:23 | call to __sync_nand_and_fetch_4 | Call to builtin function '__sync_nand_and_fetch_4' is a compiler extension and is not portable to other compilers. | +| test.c:374:3:374:30 | call to __sync_bool_compare_and_swap_4 | Call to builtin function '__sync_bool_compare_and_swap_4' is a compiler extension and is not portable to other compilers. | +| test.c:375:3:375:29 | call to __sync_val_compare_and_swap_4 | Call to builtin function '__sync_val_compare_and_swap_4' is a compiler extension and is not portable to other compilers. | +| test.c:376:3:376:26 | call to __sync_lock_test_and_set_4 | Call to builtin function '__sync_lock_test_and_set_4' is a compiler extension and is not portable to other compilers. | +| test.c:377:3:377:21 | call to __sync_lock_release_4 | Call to builtin function '__sync_lock_release_4' is a compiler extension and is not portable to other compilers. | +| test.c:405:3:405:18 | call to __builtin_alloca | Call to builtin function '__builtin_alloca' is a compiler extension and is not portable to other compilers. | diff --git a/c/misra/test/rules/RULE-1-2/test.c b/c/misra/test/rules/RULE-1-2/test.c index 86a3ae2f20..5a0759afba 100644 --- a/c/misra/test/rules/RULE-1-2/test.c +++ b/c/misra/test/rules/RULE-1-2/test.c @@ -211,14 +211,12 @@ void gf24(int f, int g) { // Reference: // https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html#Variable-Length -void gf25t(int N, int M, double out[M][N], // NON_COMPLIANT - const double in[N][M]); // NON_COMPLIANT -void gf25() { - double x[3][2]; - double y[2][3]; - gf25t(3, 2, y, - x); // in ISO C the const qualifier is formally attached - // to the element type of the array and not the array itself +void gf25(int n) { + struct S1 { + int x1[n]; // NON_COMPLIANT + int x2[5]; // COMPLIANT + int x3[]; // COMPLIANT + }; } // Reference: From ecf5e8beeba67957387fc2bdc8a6ff11b5b1d719 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 19 Sep 2024 10:57:50 +0100 Subject: [PATCH 08/62] Rule 1.2: Support aggregation of results at macro locations Add a new module/library for identifying the macro that generated an element as the primary location, and use it for Rule 1.2 to avoid overreporting. --- .../LanguageExtensionsShouldNotBeUsed.ql | 3 +- ...LanguageExtensionsShouldNotBeUsed.expected | 1 + c/misra/test/rules/RULE-1-2/test.c | 8 +++- .../codingstandards/cpp/AlertReporting.qll | 41 +++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 cpp/common/src/codingstandards/cpp/AlertReporting.qll diff --git a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql index 00a364a87e..8017f58fb5 100644 --- a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql @@ -13,8 +13,9 @@ import cpp import codingstandards.c.misra +import codingstandards.cpp.AlertReporting import codingstandards.c.Extensions from CCompilerExtension e where not isExcluded(e, Language3Package::languageExtensionsShouldNotBeUsedQuery()) -select e, e.getMessage() +select MacroUnwrapper::unwrapElement(e), e.getMessage() diff --git a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected index b82fa2bbc5..d0303f9a7f 100644 --- a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected +++ b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected @@ -48,3 +48,4 @@ | test.c:376:3:376:26 | call to __sync_lock_test_and_set_4 | Call to builtin function '__sync_lock_test_and_set_4' is a compiler extension and is not portable to other compilers. | | test.c:377:3:377:21 | call to __sync_lock_release_4 | Call to builtin function '__sync_lock_release_4' is a compiler extension and is not portable to other compilers. | | test.c:405:3:405:18 | call to __builtin_alloca | Call to builtin function '__builtin_alloca' is a compiler extension and is not portable to other compilers. | +| test.c:409:1:411:8 | #define BUILTIN __builtin_alloca( 0) | Call to builtin function '__builtin_alloca' is a compiler extension and is not portable to other compilers. | diff --git a/c/misra/test/rules/RULE-1-2/test.c b/c/misra/test/rules/RULE-1-2/test.c index 5a0759afba..439df3733c 100644 --- a/c/misra/test/rules/RULE-1-2/test.c +++ b/c/misra/test/rules/RULE-1-2/test.c @@ -404,4 +404,10 @@ void gf47() { // NON_COMPLIANT in versions < C11. void gf48() { __builtin_alloca( 0); // NON_COMPLIANT (all __builtin functions are non-compliant.) -} \ No newline at end of file +} + +#define BUILTIN \ + __builtin_alloca( \ + 0) // NON_COMPLIANT (all __builtin functions are non-compliant.) + +void gf49() { BUILTIN; } \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/AlertReporting.qll b/cpp/common/src/codingstandards/cpp/AlertReporting.qll new file mode 100644 index 0000000000..4259e1b67d --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/AlertReporting.qll @@ -0,0 +1,41 @@ +/** + * Provides a library for managing how alerts are reported. + */ + +import cpp + +signature class ResultType extends Element; + +/** + * A module for unwrapping results that occur in macro expansions. + */ +module MacroUnwrapper { + /** + * Gets a macro invocation that applies to the result element. + */ + private MacroInvocation getAMacroInvocation(ResultElement re) { + result.getAnExpandedElement() = re + } + + /** + * Gets the primary macro that generated the result element. + */ + Macro getPrimaryMacro(ResultElement re) { + exists(MacroInvocation mi | + mi = getAMacroInvocation(re) and + // No other more specific macro that expands to element + not exists(MacroInvocation otherMi | + otherMi = getAMacroInvocation(re) and otherMi.getParentInvocation() = mi + ) and + result = mi.getMacro() + ) + } + + /** + * If a result element is expanded from a macro invocation, then return the "primary" macro that + * generated the element, otherwise return the element itself. + */ + Element unwrapElement(ResultElement re) { + if exists(getPrimaryMacro(re)) then result = getPrimaryMacro(re) else result = re + } +} From 4318622161d534399d9cb4e2f531ebc9bf17dd0c Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 19 Sep 2024 11:38:15 +0100 Subject: [PATCH 09/62] Rule 1.2: Add change note --- change_notes/2024-09-19-c-extensions.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 change_notes/2024-09-19-c-extensions.md diff --git a/change_notes/2024-09-19-c-extensions.md b/change_notes/2024-09-19-c-extensions.md new file mode 100644 index 0000000000..2f78574679 --- /dev/null +++ b/change_notes/2024-09-19-c-extensions.md @@ -0,0 +1,4 @@ + - `RULE-1-2` - `LanguageExtensionsShouldNotBeUsed.ql`: + - Improve reporting by describing which language extensions are used. + - Improve reporting by aggregating results generated from a macro expansion at the generating macro location. + - Reduce false positives for the variable length array check by permitting those extensions which are included in the C99 standard. \ No newline at end of file From 104bdc7535c8c983cbde5832ab55a093e59c6def Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 24 Sep 2024 13:04:17 -0700 Subject: [PATCH 10/62] Implement Misra-c Noreturn rule package. Covers rules 17-9 through 17-11, regarding the use of the _Noreturn attribute. --- .../NonVoidReturnTypeOfNoreturnFunction.ql | 23 ++++++ ...onWithNoReturningBranchShouldBeNoreturn.ql | 24 ++++++ .../ReturnStatementInNoreturnFunction.ql | 24 ++++++ ...nVoidReturnTypeOfNoreturnFunction.expected | 1 + .../NonVoidReturnTypeOfNoreturnFunction.qlref | 1 + c/misra/test/rules/RULE-17-10/test.c | 24 ++++++ ...NoReturningBranchShouldBeNoreturn.expected | 4 + ...ithNoReturningBranchShouldBeNoreturn.qlref | 1 + c/misra/test/rules/RULE-17-11/test.c | 80 +++++++++++++++++++ ...ReturnStatementInNoreturnFunction.expected | 2 + .../ReturnStatementInNoreturnFunction.qlref | 1 + c/misra/test/rules/RULE-17-9/test.c | 45 +++++++++++ .../cpp/exclusions/c/NoReturn.qll | 61 ++++++++++++++ .../cpp/exclusions/c/RuleMetadata.qll | 3 + rule_packages/c/NoReturn.json | 55 +++++++++++++ 15 files changed, 349 insertions(+) create mode 100644 c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql create mode 100644 c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql create mode 100644 c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql create mode 100644 c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.expected create mode 100644 c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.qlref create mode 100644 c/misra/test/rules/RULE-17-10/test.c create mode 100644 c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected create mode 100644 c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.qlref create mode 100644 c/misra/test/rules/RULE-17-11/test.c create mode 100644 c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected create mode 100644 c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref create mode 100644 c/misra/test/rules/RULE-17-9/test.c create mode 100644 cpp/common/src/codingstandards/cpp/exclusions/c/NoReturn.qll create mode 100644 rule_packages/c/NoReturn.json diff --git a/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql b/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql new file mode 100644 index 0000000000..162403f579 --- /dev/null +++ b/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql @@ -0,0 +1,23 @@ +/** + * @id c/misra/non-void-return-type-of-noreturn-function + * @name RULE-17-10: A function declared with _noreturn shall have a return type of void + * @description Function declared with _noreturn will by definition not return a value, and should + * be declared to return void. + * @kind problem + * @precision very-high + * @problem.severity recommendation + * @tags external/misra/id/rule-17-10 + * external/misra/obligation/required + */ + +import cpp +import codingstandards.c.misra + +from Function f, Type returnType +where + not isExcluded(f, NoReturnPackage::nonVoidReturnTypeOfNoreturnFunctionQuery()) and + f.getASpecifier().getName() = "noreturn" and + returnType = f.getType() and + not returnType instanceof VoidType +select + f, "The function " + f.getName() + " is declared _noreturn but has a return type of " + returnType.toString() + "." diff --git a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql new file mode 100644 index 0000000000..a711658fcc --- /dev/null +++ b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql @@ -0,0 +1,24 @@ +/** + * @id c/misra/function-with-no-returning-branch-should-be-noreturn + * @name RULE-17-11: A function without a branch that returns shall be declared with _Noreturn + * @description Functions which cannot return should be declared with _Noreturn. + * @kind problem + * @precision high + * @problem.severity recommendation + * @tags external/misra/id/rule-17-11 + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.c.misra + +from Function f +where + not isExcluded(f, NoReturnPackage::returnStatementInNoreturnFunctionQuery()) and + not f.getASpecifier().getName() = "noreturn" and + not exists(ReturnStmt s | + f = s.getEnclosingFunction() and + s.getBasicBlock().isReachable() + ) +select + f, "The function " + f.getName() + " cannot return and should be declared attribute _Noreturn." diff --git a/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql b/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql new file mode 100644 index 0000000000..0c291c20af --- /dev/null +++ b/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql @@ -0,0 +1,24 @@ +/** + * @id c/misra/return-statement-in-noreturn-function + * @name RULE-17-9: Verify that a function declared with _Noreturn does not return + * @description Returning inside a function declared with _Noreturn is undefined behavior. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-17-9 + * external/misra/obligation/mandatory + */ + +import cpp +import codingstandards.c.misra + +from Function f +where + not isExcluded(f, NoReturnPackage::returnStatementInNoreturnFunctionQuery()) and + f.getASpecifier().getName() = "noreturn" and + exists(ReturnStmt s | + f = s.getEnclosingFunction() and + s.getBasicBlock().isReachable() + ) +select + f, "The function " + f.getName() + " declared with attribute _Noreturn returns a value." diff --git a/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.expected b/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.expected new file mode 100644 index 0000000000..2ec1a0ac6c --- /dev/null +++ b/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.expected @@ -0,0 +1 @@ +No expected results have yet been specified \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.qlref b/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.qlref new file mode 100644 index 0000000000..6726b6957a --- /dev/null +++ b/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.qlref @@ -0,0 +1 @@ +rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-10/test.c b/c/misra/test/rules/RULE-17-10/test.c new file mode 100644 index 0000000000..5e3aadf165 --- /dev/null +++ b/c/misra/test/rules/RULE-17-10/test.c @@ -0,0 +1,24 @@ +#include "stdlib.h" + +void f1(); // COMPLIANT +int f2(); // COMPLIANT +_Noreturn void f3(); // COMPLIANT +_Noreturn int f4(); // NON-COMPLIANT + +void f5() { // COMPLIANT +} + +int f6() { // COMPLIANT + return 0; +} + +_Noreturn void f7() { // COMPLIANT + abort(); +} + +_Noreturn int f8() { // NON-COMPLIANT + abort(); + return 0; +} + +_Noreturn void* f9(); // NON-COMPLIANT \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected new file mode 100644 index 0000000000..5141f0c9c3 --- /dev/null +++ b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected @@ -0,0 +1,4 @@ +| test.c:7:6:7:21 | test_noreturn_f2 | The function test_noreturn_f2 cannot return and should be declared attribute _Noreturn. | +| test.c:19:6:19:21 | test_noreturn_f4 | The function test_noreturn_f4 cannot return and should be declared attribute _Noreturn. | +| test.c:48:6:48:21 | test_noreturn_f8 | The function test_noreturn_f8 cannot return and should be declared attribute _Noreturn. | +| test.c:64:6:64:22 | test_noreturn_f10 | The function test_noreturn_f10 cannot return and should be declared attribute _Noreturn. | diff --git a/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.qlref b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.qlref new file mode 100644 index 0000000000..feb6f40804 --- /dev/null +++ b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.qlref @@ -0,0 +1 @@ +rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-11/test.c b/c/misra/test/rules/RULE-17-11/test.c new file mode 100644 index 0000000000..3d0144d6f0 --- /dev/null +++ b/c/misra/test/rules/RULE-17-11/test.c @@ -0,0 +1,80 @@ +#include "stdlib.h" + +_Noreturn void test_noreturn_f1(int i) { // COMPLIANT + abort(); +} + +void test_noreturn_f2(int i) { // NON_COMPLIANT + abort(); +} + + +_Noreturn void test_noreturn_f3(int i) { // COMPLIANT + if (i > 0) { + abort(); + } + exit(1); +} + +void test_noreturn_f4(int i) { // NON_COMPLIANT + if (i > 0) { + abort(); + } + exit(1); +} + +void test_noreturn_f5(int i) { // COMPLIANT + if (i > 0) { + return; + } + exit(1); +} + +void test_noreturn_f6(int i) { // COMPLIANT + if (i > 0) { + abort(); + } + if (i < 0) { + abort(); + } +} + +void test_noreturn_f7(int i) { // COMPLIANT + if (i > 0) { + abort(); + } +} + +void test_noreturn_f8(int i) { // NON_COMPLIANT + if (i > 0) { + abort(); + } else { + abort(); + } +} + +_Noreturn void test_noreturn_f9(int i) { // COMPLIANT + if (i > 0) { + abort(); + } else { + abort(); + } +} + +void test_noreturn_f10(int i) { // NON_COMPLIANT + if (i > 0) { + abort(); + } + while (1) { + i = 5; + } +} + +_Noreturn void test_noreturn_f11(int i) { // COMPLIANT + if (i > 0) { + abort(); + } + while (1) { + i = 5; + } +} diff --git a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected new file mode 100644 index 0000000000..1e6a6ab180 --- /dev/null +++ b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected @@ -0,0 +1,2 @@ +| test.c:7:16:7:31 | test_noreturn_f2 | The function test_noreturn_f2 declared with attribute _Noreturn returns a value. | +| test.c:32:16:32:31 | test_noreturn_f5 | The function test_noreturn_f5 declared with attribute _Noreturn returns a value. | diff --git a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref new file mode 100644 index 0000000000..eaa647d8a4 --- /dev/null +++ b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref @@ -0,0 +1 @@ +rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-9/test.c b/c/misra/test/rules/RULE-17-9/test.c new file mode 100644 index 0000000000..c3ff575672 --- /dev/null +++ b/c/misra/test/rules/RULE-17-9/test.c @@ -0,0 +1,45 @@ +#include "stdlib.h" + +_Noreturn void test_noreturn_f1(int i) { // COMPLIANT + abort(); +} + +_Noreturn void test_noreturn_f2(int i) { // NON_COMPLIANT + if (i > 0) { + abort(); + } + if (i < 0) { + abort(); + } +} + +_Noreturn void test_noreturn_f3(int i) { // COMPLIANT + if (i > 0) { + abort(); + } + exit(1); +} + +void test_noreturn_f4(int i) { // COMPLIANT + if (i > 0) { + abort(); + } + if (i < 0) { + abort(); + } +} + +_Noreturn void test_noreturn_f5(int i) { // NON_COMPLIANT + if (i > 0) { + abort(); + } +} + +_Noreturn void test_noreturn_f6(int i) { // COMPLIANT + if (i > 0) { + abort(); + } + while (1) { + i = 5; + } +} diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/NoReturn.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/NoReturn.qll new file mode 100644 index 0000000000..07b9360213 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/NoReturn.qll @@ -0,0 +1,61 @@ +//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ +import cpp +import RuleMetadata +import codingstandards.cpp.exclusions.RuleMetadata + +newtype NoReturnQuery = + TNonVoidReturnTypeOfNoreturnFunctionQuery() or + TFunctionWithNoReturningBranchShouldBeNoreturnQuery() or + TReturnStatementInNoreturnFunctionQuery() + +predicate isNoReturnQueryMetadata(Query query, string queryId, string ruleId, string category) { + query = + // `Query` instance for the `nonVoidReturnTypeOfNoreturnFunction` query + NoReturnPackage::nonVoidReturnTypeOfNoreturnFunctionQuery() and + queryId = + // `@id` for the `nonVoidReturnTypeOfNoreturnFunction` query + "c/misra/non-void-return-type-of-noreturn-function" and + ruleId = "RULE-17-10" and + category = "required" + or + query = + // `Query` instance for the `functionWithNoReturningBranchShouldBeNoreturn` query + NoReturnPackage::functionWithNoReturningBranchShouldBeNoreturnQuery() and + queryId = + // `@id` for the `functionWithNoReturningBranchShouldBeNoreturn` query + "c/misra/function-with-no-returning-branch-should-be-noreturn" and + ruleId = "RULE-17-11" and + category = "advisory" + or + query = + // `Query` instance for the `returnStatementInNoreturnFunction` query + NoReturnPackage::returnStatementInNoreturnFunctionQuery() and + queryId = + // `@id` for the `returnStatementInNoreturnFunction` query + "c/misra/return-statement-in-noreturn-function" and + ruleId = "RULE-17-9" and + category = "mandatory" +} + +module NoReturnPackage { + Query nonVoidReturnTypeOfNoreturnFunctionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `nonVoidReturnTypeOfNoreturnFunction` query + TQueryC(TNoReturnPackageQuery(TNonVoidReturnTypeOfNoreturnFunctionQuery())) + } + + Query functionWithNoReturningBranchShouldBeNoreturnQuery() { + //autogenerate `Query` type + result = + // `Query` type for `functionWithNoReturningBranchShouldBeNoreturn` query + TQueryC(TNoReturnPackageQuery(TFunctionWithNoReturningBranchShouldBeNoreturnQuery())) + } + + Query returnStatementInNoreturnFunctionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `returnStatementInNoreturnFunction` query + TQueryC(TNoReturnPackageQuery(TReturnStatementInNoreturnFunctionQuery())) + } +} diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll index c2771f4171..b3ed02f204 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll @@ -42,6 +42,7 @@ import Memory1 import Memory2 import Memory3 import Misc +import NoReturn import OutOfBounds import Pointers1 import Pointers2 @@ -113,6 +114,7 @@ newtype TCQuery = TMemory2PackageQuery(Memory2Query q) or TMemory3PackageQuery(Memory3Query q) or TMiscPackageQuery(MiscQuery q) or + TNoReturnPackageQuery(NoReturnQuery q) or TOutOfBoundsPackageQuery(OutOfBoundsQuery q) or TPointers1PackageQuery(Pointers1Query q) or TPointers2PackageQuery(Pointers2Query q) or @@ -184,6 +186,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat isMemory2QueryMetadata(query, queryId, ruleId, category) or isMemory3QueryMetadata(query, queryId, ruleId, category) or isMiscQueryMetadata(query, queryId, ruleId, category) or + isNoReturnQueryMetadata(query, queryId, ruleId, category) or isOutOfBoundsQueryMetadata(query, queryId, ruleId, category) or isPointers1QueryMetadata(query, queryId, ruleId, category) or isPointers2QueryMetadata(query, queryId, ruleId, category) or diff --git a/rule_packages/c/NoReturn.json b/rule_packages/c/NoReturn.json new file mode 100644 index 0000000000..1cb4d02ab4 --- /dev/null +++ b/rule_packages/c/NoReturn.json @@ -0,0 +1,55 @@ +{ + "MISRA-C-2012": { + "RULE-17-10": { + "properties": { + "obligation": "required" + }, + "queries": [ + { + "description": "Function declared with _noreturn will by definition not return a value, and should be declared to return void.", + "kind": "problem", + "name": "A function declared with _noreturn shall have a return type of void", + "precision": "very-high", + "severity": "recommendation", + "short_name": "NonVoidReturnTypeOfNoreturnFunction", + "tags": [] + } + ], + "title": "A function declared with _noreturn shall have a return type of void" + }, + "RULE-17-11": { + "properties": { + "obligation": "advisory" + }, + "queries": [ + { + "description": "Functions which cannot return should be declared with _Noreturn.", + "kind": "problem", + "name": "A function without a branch that returns shall be declared with _Noreturn", + "precision": "high", + "severity": "recommendation", + "short_name": "FunctionWithNoReturningBranchShouldBeNoreturn", + "tags": [] + } + ], + "title": "A function without a branch that returns shall be declared with _Noreturn" + }, + "RULE-17-9": { + "properties": { + "obligation": "mandatory" + }, + "queries": [ + { + "description": "Returning inside a function declared with _Noreturn is undefined behavior.", + "kind": "problem", + "name": "Verify that a function declared with _Noreturn does not return", + "precision": "very-high", + "severity": "error", + "short_name": "ReturnStatementInNoreturnFunction", + "tags": [] + } + ], + "title": "Verify that a function declared with _Noreturn does not return" + } + } +} \ No newline at end of file From 778db73655fbbaebbcec2ec0a18958c1ae566e28 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 24 Sep 2024 13:43:47 -0700 Subject: [PATCH 11/62] Fix false positives by supporting __attribute__((noreturn)), format. Use shared qll to avoid duplicating logic of detecting noreturn across both specifiers and attributes, and to detect a possible returning stmt. --- c/common/src/codingstandards/c/Noreturn.qll | 22 +++++++++++++++++++ .../NonVoidReturnTypeOfNoreturnFunction.ql | 9 ++++---- ...onWithNoReturningBranchShouldBeNoreturn.ql | 14 ++++++------ .../ReturnStatementInNoreturnFunction.ql | 12 ++++------ ...nVoidReturnTypeOfNoreturnFunction.expected | 5 ++++- c/misra/test/rules/RULE-17-10/test.c | 10 +++++---- ...NoReturningBranchShouldBeNoreturn.expected | 6 ++--- c/misra/test/rules/RULE-17-11/test.c | 13 ++++++++++- ...ReturnStatementInNoreturnFunction.expected | 1 + c/misra/test/rules/RULE-17-9/test.c | 10 +++++++++ 10 files changed, 74 insertions(+), 28 deletions(-) create mode 100644 c/common/src/codingstandards/c/Noreturn.qll diff --git a/c/common/src/codingstandards/c/Noreturn.qll b/c/common/src/codingstandards/c/Noreturn.qll new file mode 100644 index 0000000000..eabe86b56e --- /dev/null +++ b/c/common/src/codingstandards/c/Noreturn.qll @@ -0,0 +1,22 @@ +import cpp + +/** + * A function marked with _Noreturn or __attribute((noreturn)) + */ +class NoreturnFunction extends Function { + NoreturnFunction() { + this.getASpecifier().getName() = "noreturn" or + this.getAnAttribute().getName() = "noreturn" + } +} + +/** + * A function that may complete normally, and/or contains an explicit reachable + * return statement. + */ +predicate mayReturn(Function function) { + exists(ReturnStmt s | + function = s.getEnclosingFunction() and + s.getBasicBlock().isReachable() + ) +} diff --git a/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql b/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql index 162403f579..3e6f2340fd 100644 --- a/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql +++ b/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql @@ -12,12 +12,13 @@ import cpp import codingstandards.c.misra +import codingstandards.c.Noreturn -from Function f, Type returnType +from NoreturnFunction f, Type returnType where not isExcluded(f, NoReturnPackage::nonVoidReturnTypeOfNoreturnFunctionQuery()) and - f.getASpecifier().getName() = "noreturn" and returnType = f.getType() and not returnType instanceof VoidType -select - f, "The function " + f.getName() + " is declared _noreturn but has a return type of " + returnType.toString() + "." +select f, + "The function " + f.getName() + " is declared _noreturn but has a return type of " + + returnType.toString() + "." diff --git a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql index a711658fcc..c5d342c015 100644 --- a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql +++ b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql @@ -11,14 +11,14 @@ import cpp import codingstandards.c.misra +import codingstandards.c.Noreturn from Function f where not isExcluded(f, NoReturnPackage::returnStatementInNoreturnFunctionQuery()) and - not f.getASpecifier().getName() = "noreturn" and - not exists(ReturnStmt s | - f = s.getEnclosingFunction() and - s.getBasicBlock().isReachable() - ) -select - f, "The function " + f.getName() + " cannot return and should be declared attribute _Noreturn." + not f instanceof NoreturnFunction and + not mayReturn(f) and + f.hasDefinition() and + f.getName() != "main" // Allowed exception; _Noreturn main() is undefined behavior. +select f, + "The function " + f.getName() + " cannot return and should be declared attribute _Noreturn." diff --git a/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql b/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql index 0c291c20af..7c23cf306f 100644 --- a/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql +++ b/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql @@ -11,14 +11,10 @@ import cpp import codingstandards.c.misra +import codingstandards.c.Noreturn -from Function f +from NoreturnFunction f where not isExcluded(f, NoReturnPackage::returnStatementInNoreturnFunctionQuery()) and - f.getASpecifier().getName() = "noreturn" and - exists(ReturnStmt s | - f = s.getEnclosingFunction() and - s.getBasicBlock().isReachable() - ) -select - f, "The function " + f.getName() + " declared with attribute _Noreturn returns a value." + mayReturn(f) +select f, "The function " + f.getName() + " declared with attribute _Noreturn returns a value." diff --git a/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.expected b/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.expected index 2ec1a0ac6c..a94e37baa4 100644 --- a/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.expected +++ b/c/misra/test/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.expected @@ -1 +1,4 @@ -No expected results have yet been specified \ No newline at end of file +| test.c:6:15:6:16 | f4 | The function f4 is declared _noreturn but has a return type of int. | +| test.c:19:15:19:16 | f8 | The function f8 is declared _noreturn but has a return type of int. | +| test.c:24:17:24:18 | f9 | The function f9 is declared _noreturn but has a return type of void *. | +| test.c:26:31:26:33 | f10 | The function f10 is declared _noreturn but has a return type of int. | diff --git a/c/misra/test/rules/RULE-17-10/test.c b/c/misra/test/rules/RULE-17-10/test.c index 5e3aadf165..b5fc988af2 100644 --- a/c/misra/test/rules/RULE-17-10/test.c +++ b/c/misra/test/rules/RULE-17-10/test.c @@ -1,9 +1,9 @@ #include "stdlib.h" -void f1(); // COMPLIANT -int f2(); // COMPLIANT +void f1(); // COMPLIANT +int f2(); // COMPLIANT _Noreturn void f3(); // COMPLIANT -_Noreturn int f4(); // NON-COMPLIANT +_Noreturn int f4(); // NON-COMPLIANT void f5() { // COMPLIANT } @@ -21,4 +21,6 @@ _Noreturn int f8() { // NON-COMPLIANT return 0; } -_Noreturn void* f9(); // NON-COMPLIANT \ No newline at end of file +_Noreturn void *f9(); // NON-COMPLIANT + +__attribute__((noreturn)) int f10(); // NON-COMPLIANT \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected index 5141f0c9c3..15389bfcdd 100644 --- a/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected +++ b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected @@ -1,4 +1,4 @@ | test.c:7:6:7:21 | test_noreturn_f2 | The function test_noreturn_f2 cannot return and should be declared attribute _Noreturn. | -| test.c:19:6:19:21 | test_noreturn_f4 | The function test_noreturn_f4 cannot return and should be declared attribute _Noreturn. | -| test.c:48:6:48:21 | test_noreturn_f8 | The function test_noreturn_f8 cannot return and should be declared attribute _Noreturn. | -| test.c:64:6:64:22 | test_noreturn_f10 | The function test_noreturn_f10 cannot return and should be declared attribute _Noreturn. | +| test.c:18:6:18:21 | test_noreturn_f4 | The function test_noreturn_f4 cannot return and should be declared attribute _Noreturn. | +| test.c:47:6:47:21 | test_noreturn_f8 | The function test_noreturn_f8 cannot return and should be declared attribute _Noreturn. | +| test.c:63:6:63:22 | test_noreturn_f10 | The function test_noreturn_f10 cannot return and should be declared attribute _Noreturn. | diff --git a/c/misra/test/rules/RULE-17-11/test.c b/c/misra/test/rules/RULE-17-11/test.c index 3d0144d6f0..1ecc2b1c44 100644 --- a/c/misra/test/rules/RULE-17-11/test.c +++ b/c/misra/test/rules/RULE-17-11/test.c @@ -8,7 +8,6 @@ void test_noreturn_f2(int i) { // NON_COMPLIANT abort(); } - _Noreturn void test_noreturn_f3(int i) { // COMPLIANT if (i > 0) { abort(); @@ -78,3 +77,15 @@ _Noreturn void test_noreturn_f11(int i) { // COMPLIANT i = 5; } } + +void test_noreturn_f12(); // COMPLIANT + +__attribute__((noreturn)) void test_noreturn_f13(int i) { // COMPLIANT + abort(); +} + +// Allowed by exception. It is undefined behavior for main() to be declared with +// noreturn. +int main(char **argv, int argc) { // COMPLIANT + abort(); +} \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected index 1e6a6ab180..9775f797de 100644 --- a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected +++ b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected @@ -1,2 +1,3 @@ | test.c:7:16:7:31 | test_noreturn_f2 | The function test_noreturn_f2 declared with attribute _Noreturn returns a value. | | test.c:32:16:32:31 | test_noreturn_f5 | The function test_noreturn_f5 declared with attribute _Noreturn returns a value. | +| test.c:47:32:47:47 | test_noreturn_f7 | The function test_noreturn_f7 declared with attribute _Noreturn returns a value. | diff --git a/c/misra/test/rules/RULE-17-9/test.c b/c/misra/test/rules/RULE-17-9/test.c index c3ff575672..05ff410562 100644 --- a/c/misra/test/rules/RULE-17-9/test.c +++ b/c/misra/test/rules/RULE-17-9/test.c @@ -43,3 +43,13 @@ _Noreturn void test_noreturn_f6(int i) { // COMPLIANT i = 5; } } + +__attribute__((noreturn)) void test_noreturn_f7(int i) { // NON_COMPLIANT + if (i > 0) { + abort(); + } +} + +__attribute__((noreturn)) void test_noreturn_f8(int i) { // COMPLIANT + abort(); +} \ No newline at end of file From 33223fa18bf0fb2a6b57525866c7c6219020e715 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 26 Sep 2024 23:25:12 +0000 Subject: [PATCH 12/62] Bump actions/download-artifact Bumps the github_actions group with 1 update in the /.github/workflows directory: [actions/download-artifact](https://github.com/actions/download-artifact). Updates `actions/download-artifact` from 2 to 4 - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v2...v4) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production dependency-group: github_actions ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql_unit_tests.yml | 2 +- .github/workflows/standard_library_upgrade_tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql_unit_tests.yml b/.github/workflows/codeql_unit_tests.yml index 62660d973d..a6488a728c 100644 --- a/.github/workflows/codeql_unit_tests.yml +++ b/.github/workflows/codeql_unit_tests.yml @@ -164,7 +164,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Collect test results - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 - name: Validate test results run: | diff --git a/.github/workflows/standard_library_upgrade_tests.yml b/.github/workflows/standard_library_upgrade_tests.yml index 5402dc9105..35717b7b4e 100644 --- a/.github/workflows/standard_library_upgrade_tests.yml +++ b/.github/workflows/standard_library_upgrade_tests.yml @@ -162,7 +162,7 @@ jobs: python-version: "3.9" - name: Collect test results - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 - name: Validate test results shell: python From c8e50910bb1c292dbb395078aec2aef2f7f078b3 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Fri, 27 Sep 2024 13:29:11 -0700 Subject: [PATCH 13/62] Address feedback --- ...unctionNoReturnAttributeCondition.expected | 3 ++ .../FunctionNoReturnAttributeCondition.ql | 4 +++ .../test.c | 28 +++++++++++++++++++ .../NonVoidReturnTypeOfNoreturnFunction.ql | 6 ++-- ...onWithNoReturningBranchShouldBeNoreturn.ql | 6 ++-- .../ReturnStatementInNoreturnFunction.ql | 13 +++++---- ...NoReturningBranchShouldBeNoreturn.expected | 2 ++ c/misra/test/rules/RULE-17-11/test.c | 13 +++++++++ ...ReturnStatementInNoreturnFunction.expected | 3 -- .../ReturnStatementInNoreturnFunction.testref | 1 + .../src/codingstandards/cpp}/Noreturn.qll | 0 .../FunctionNoReturnAttributeCondition.qll | 23 ++++++++++----- rule_packages/c/NoReturn.json | 7 +++-- 13 files changed, 86 insertions(+), 23 deletions(-) create mode 100644 c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.expected create mode 100644 c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.ql rename c/{misra/test/rules/RULE-17-9 => common/test/rules/functionnoreturnattributecondition}/test.c (61%) delete mode 100644 c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected create mode 100644 c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.testref rename {c/common/src/codingstandards/c => cpp/common/src/codingstandards/cpp}/Noreturn.qll (100%) diff --git a/c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.expected b/c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.expected new file mode 100644 index 0000000000..5aede0a5ba --- /dev/null +++ b/c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.expected @@ -0,0 +1,3 @@ +| test.c:9:16:9:31 | test_noreturn_f2 | The function test_noreturn_f2 declared with attribute _Noreturn returns a value. | +| test.c:34:16:34:31 | test_noreturn_f5 | The function test_noreturn_f5 declared with attribute _Noreturn returns a value. | +| test.c:49:32:49:47 | test_noreturn_f7 | The function test_noreturn_f7 declared with attribute _Noreturn returns a value. | diff --git a/c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.ql b/c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.ql new file mode 100644 index 0000000000..4af4aeceaf --- /dev/null +++ b/c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.functionnoreturnattributecondition.FunctionNoReturnAttributeCondition + +class TestFileQuery extends FunctionNoReturnAttributeConditionSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-17-9/test.c b/c/common/test/rules/functionnoreturnattributecondition/test.c similarity index 61% rename from c/misra/test/rules/RULE-17-9/test.c rename to c/common/test/rules/functionnoreturnattributecondition/test.c index 05ff410562..8299c0cc89 100644 --- a/c/misra/test/rules/RULE-17-9/test.c +++ b/c/common/test/rules/functionnoreturnattributecondition/test.c @@ -1,4 +1,6 @@ #include "stdlib.h" +#include "threads.h" +#include "setjmp.h" _Noreturn void test_noreturn_f1(int i) { // COMPLIANT abort(); @@ -52,4 +54,30 @@ __attribute__((noreturn)) void test_noreturn_f7(int i) { // NON_COMPLIANT __attribute__((noreturn)) void test_noreturn_f8(int i) { // COMPLIANT abort(); +} + +_Noreturn void test_noreturn_f9(int i) { // COMPLIANT + test_noreturn_f1(i); +} + +_Noreturn void test_noreturn_f10(int i) { // COMPLIANT + switch(i) { + case 0: + abort(); break; + case 1: + exit(0); break; + case 2: + _Exit(0); break; + case 3: + quick_exit(0); break; + case 4: + thrd_exit(0); break; + default: + jmp_buf jb; + longjmp(jb, 0); + } +} + +_Noreturn void test_noreturn_f11(int i) { // COMPLIANT + return test_noreturn_f11(i); } \ No newline at end of file diff --git a/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql b/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql index 3e6f2340fd..68c5faeb1b 100644 --- a/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql +++ b/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql @@ -7,18 +7,20 @@ * @precision very-high * @problem.severity recommendation * @tags external/misra/id/rule-17-10 + * correctness * external/misra/obligation/required */ import cpp import codingstandards.c.misra -import codingstandards.c.Noreturn +import codingstandards.cpp.Noreturn from NoreturnFunction f, Type returnType where not isExcluded(f, NoReturnPackage::nonVoidReturnTypeOfNoreturnFunctionQuery()) and returnType = f.getType() and - not returnType instanceof VoidType + not returnType instanceof VoidType and + not f.isCompilerGenerated() select f, "The function " + f.getName() + " is declared _noreturn but has a return type of " + returnType.toString() + "." diff --git a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql index c5d342c015..5563822f9c 100644 --- a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql +++ b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql @@ -6,12 +6,13 @@ * @precision high * @problem.severity recommendation * @tags external/misra/id/rule-17-11 + * correctness * external/misra/obligation/advisory */ import cpp import codingstandards.c.misra -import codingstandards.c.Noreturn +import codingstandards.cpp.Noreturn from Function f where @@ -19,6 +20,7 @@ where not f instanceof NoreturnFunction and not mayReturn(f) and f.hasDefinition() and - f.getName() != "main" // Allowed exception; _Noreturn main() is undefined behavior. + not f.getName() = "main" and // Allowed exception; _Noreturn main() is undefined behavior. + not f.isCompilerGenerated() select f, "The function " + f.getName() + " cannot return and should be declared attribute _Noreturn." diff --git a/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql b/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql index 7c23cf306f..360be01b7c 100644 --- a/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql +++ b/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql @@ -6,15 +6,16 @@ * @precision very-high * @problem.severity error * @tags external/misra/id/rule-17-9 + * correctness * external/misra/obligation/mandatory */ import cpp import codingstandards.c.misra -import codingstandards.c.Noreturn +import codingstandards.cpp.rules.functionnoreturnattributecondition.FunctionNoReturnAttributeCondition -from NoreturnFunction f -where - not isExcluded(f, NoReturnPackage::returnStatementInNoreturnFunctionQuery()) and - mayReturn(f) -select f, "The function " + f.getName() + " declared with attribute _Noreturn returns a value." +class ReturnStatementInNoreturnFunctionQuery extends FunctionNoReturnAttributeConditionSharedQuery { + ReturnStatementInNoreturnFunctionQuery() { + this = NoReturnPackage::returnStatementInNoreturnFunctionQuery() + } +} diff --git a/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected index 15389bfcdd..fe275e9497 100644 --- a/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected +++ b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected @@ -2,3 +2,5 @@ | test.c:18:6:18:21 | test_noreturn_f4 | The function test_noreturn_f4 cannot return and should be declared attribute _Noreturn. | | test.c:47:6:47:21 | test_noreturn_f8 | The function test_noreturn_f8 cannot return and should be declared attribute _Noreturn. | | test.c:63:6:63:22 | test_noreturn_f10 | The function test_noreturn_f10 cannot return and should be declared attribute _Noreturn. | +| test.c:97:6:97:22 | test_noreturn_f15 | The function test_noreturn_f15 cannot return and should be declared attribute _Noreturn. | +| test.c:101:6:101:22 | test_noreturn_f16 | The function test_noreturn_f16 cannot return and should be declared attribute _Noreturn. | diff --git a/c/misra/test/rules/RULE-17-11/test.c b/c/misra/test/rules/RULE-17-11/test.c index 1ecc2b1c44..7baaea5821 100644 --- a/c/misra/test/rules/RULE-17-11/test.c +++ b/c/misra/test/rules/RULE-17-11/test.c @@ -88,4 +88,17 @@ __attribute__((noreturn)) void test_noreturn_f13(int i) { // COMPLIANT // noreturn. int main(char **argv, int argc) { // COMPLIANT abort(); +} + +_Noreturn void test_noreturn_f14(int i) { // COMPLIANT + test_noreturn_f1(i); +} + +void test_noreturn_f15(int i) { // NON_COMPLIANT + test_noreturn_f1(i); +} + +void test_noreturn_f16(int i) { // NON_COMPLIANT + // Infinite tail recursion + test_noreturn_f16(i); } \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected deleted file mode 100644 index 9775f797de..0000000000 --- a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.expected +++ /dev/null @@ -1,3 +0,0 @@ -| test.c:7:16:7:31 | test_noreturn_f2 | The function test_noreturn_f2 declared with attribute _Noreturn returns a value. | -| test.c:32:16:32:31 | test_noreturn_f5 | The function test_noreturn_f5 declared with attribute _Noreturn returns a value. | -| test.c:47:32:47:47 | test_noreturn_f7 | The function test_noreturn_f7 declared with attribute _Noreturn returns a value. | diff --git a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.testref b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.testref new file mode 100644 index 0000000000..09a6d90538 --- /dev/null +++ b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.testref @@ -0,0 +1 @@ +c/common/test/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.ql \ No newline at end of file diff --git a/c/common/src/codingstandards/c/Noreturn.qll b/cpp/common/src/codingstandards/cpp/Noreturn.qll similarity index 100% rename from c/common/src/codingstandards/c/Noreturn.qll rename to cpp/common/src/codingstandards/cpp/Noreturn.qll diff --git a/cpp/common/src/codingstandards/cpp/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.qll b/cpp/common/src/codingstandards/cpp/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.qll index 2b910612cb..e2c210282b 100644 --- a/cpp/common/src/codingstandards/cpp/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.qll +++ b/cpp/common/src/codingstandards/cpp/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.qll @@ -5,20 +5,29 @@ import cpp import codingstandards.cpp.Customizations import codingstandards.cpp.Exclusions +import codingstandards.cpp.Noreturn abstract class FunctionNoReturnAttributeConditionSharedQuery extends Query { } Query getQuery() { result instanceof FunctionNoReturnAttributeConditionSharedQuery } +/** + * `noreturn` functions are declared differently in c/c++. Attempt to match + * the description to the file; low risk if it chooses incorrectly. + */ +string describeNoreturn(Function f) { + if f.getFile().getExtension() = ["c", "C", "h", "H"] + then result = "_Noreturn" + else result = "[[noreturn]]" +} + /** * This checks that the return statement is reachable from the function entry point */ -query predicate problems(Function f, string message) { +query predicate problems(NoreturnFunction f, string message) { not isExcluded(f, getQuery()) and - f.getAnAttribute().getName() = "noreturn" and - exists(ReturnStmt s | - f = s.getEnclosingFunction() and - s.getBasicBlock().isReachable() - ) and - message = "The function " + f.getName() + " declared with attribute [[noreturn]] returns a value." + mayReturn(f) and + not f.isCompilerGenerated() and + message = + "The function " + f.getName() + " declared with attribute " + describeNoreturn(f) + " returns a value." } diff --git a/rule_packages/c/NoReturn.json b/rule_packages/c/NoReturn.json index 1cb4d02ab4..d06068f376 100644 --- a/rule_packages/c/NoReturn.json +++ b/rule_packages/c/NoReturn.json @@ -12,7 +12,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "NonVoidReturnTypeOfNoreturnFunction", - "tags": [] + "tags": ["correctness"] } ], "title": "A function declared with _noreturn shall have a return type of void" @@ -29,7 +29,7 @@ "precision": "high", "severity": "recommendation", "short_name": "FunctionWithNoReturningBranchShouldBeNoreturn", - "tags": [] + "tags": ["correctness"] } ], "title": "A function without a branch that returns shall be declared with _Noreturn" @@ -46,7 +46,8 @@ "precision": "very-high", "severity": "error", "short_name": "ReturnStatementInNoreturnFunction", - "tags": [] + "tags": ["correctness"], + "shared_implementation_short_name": "FunctionNoReturnAttributeCondition" } ], "title": "Verify that a function declared with _Noreturn does not return" From 8991e5f98183d015d02e64b8d47f1748d70b7250 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Fri, 27 Sep 2024 13:35:39 -0700 Subject: [PATCH 14/62] Fix format --- .../functionnoreturnattributecondition/test.c | 35 +++++++++++-------- .../FunctionNoReturnAttributeCondition.qll | 3 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/c/common/test/rules/functionnoreturnattributecondition/test.c b/c/common/test/rules/functionnoreturnattributecondition/test.c index 8299c0cc89..1b0ba759e1 100644 --- a/c/common/test/rules/functionnoreturnattributecondition/test.c +++ b/c/common/test/rules/functionnoreturnattributecondition/test.c @@ -1,6 +1,6 @@ +#include "setjmp.h" #include "stdlib.h" #include "threads.h" -#include "setjmp.h" _Noreturn void test_noreturn_f1(int i) { // COMPLIANT abort(); @@ -61,20 +61,25 @@ _Noreturn void test_noreturn_f9(int i) { // COMPLIANT } _Noreturn void test_noreturn_f10(int i) { // COMPLIANT - switch(i) { - case 0: - abort(); break; - case 1: - exit(0); break; - case 2: - _Exit(0); break; - case 3: - quick_exit(0); break; - case 4: - thrd_exit(0); break; - default: - jmp_buf jb; - longjmp(jb, 0); + switch (i) { + case 0: + abort(); + break; + case 1: + exit(0); + break; + case 2: + _Exit(0); + break; + case 3: + quick_exit(0); + break; + case 4: + thrd_exit(0); + break; + default: + jmp_buf jb; + longjmp(jb, 0); } } diff --git a/cpp/common/src/codingstandards/cpp/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.qll b/cpp/common/src/codingstandards/cpp/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.qll index e2c210282b..bb54a31df6 100644 --- a/cpp/common/src/codingstandards/cpp/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.qll +++ b/cpp/common/src/codingstandards/cpp/rules/functionnoreturnattributecondition/FunctionNoReturnAttributeCondition.qll @@ -29,5 +29,6 @@ query predicate problems(NoreturnFunction f, string message) { mayReturn(f) and not f.isCompilerGenerated() and message = - "The function " + f.getName() + " declared with attribute " + describeNoreturn(f) + " returns a value." + "The function " + f.getName() + " declared with attribute " + describeNoreturn(f) + + " returns a value." } From b297513482e44fc24126b2c87250ace8fdc49338 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Fri, 27 Sep 2024 14:31:29 -0700 Subject: [PATCH 15/62] Fix tests --- .../test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref | 1 - 1 file changed, 1 deletion(-) delete mode 100644 c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref diff --git a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref b/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref deleted file mode 100644 index eaa647d8a4..0000000000 --- a/c/misra/test/rules/RULE-17-9/ReturnStatementInNoreturnFunction.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql \ No newline at end of file From 6f860fcd49ccb88756ecc39c9c81d62093458aeb Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Mon, 30 Sep 2024 07:51:17 -0700 Subject: [PATCH 16/62] Add changelog; tweaks based on MRVA results. --- .../FunctionWithNoReturningBranchShouldBeNoreturn.ql | 7 +++++-- change_notes/2024-09-28-improved-noreturn-rules.md | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 change_notes/2024-09-28-improved-noreturn-rules.md diff --git a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql index 5563822f9c..7383746d05 100644 --- a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql +++ b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql @@ -16,11 +16,14 @@ import codingstandards.cpp.Noreturn from Function f where - not isExcluded(f, NoReturnPackage::returnStatementInNoreturnFunctionQuery()) and + not isExcluded(f, NoReturnPackage::functionWithNoReturningBranchShouldBeNoreturnQuery()) and not f instanceof NoreturnFunction and not mayReturn(f) and f.hasDefinition() and not f.getName() = "main" and // Allowed exception; _Noreturn main() is undefined behavior. + // Harden against c++ cases. + not f.isFromUninstantiatedTemplate(_) and + not f.isDeleted() and not f.isCompilerGenerated() select f, - "The function " + f.getName() + " cannot return and should be declared attribute _Noreturn." + "The function " + f.getName() + " cannot return and should be declared as _Noreturn." diff --git a/change_notes/2024-09-28-improved-noreturn-rules.md b/change_notes/2024-09-28-improved-noreturn-rules.md new file mode 100644 index 0000000000..99fb4a0f46 --- /dev/null +++ b/change_notes/2024-09-28-improved-noreturn-rules.md @@ -0,0 +1,3 @@ + - `A7-6-1`, `MSC53-CPP`, `RULE-9-6-4` - `FunctionNoReturnAttbrituteCondition.qll` + - Analysis expanded from functions with "noreturn" attribute, now includes the "noreturn" specifier as well to handle new c rules. No difference in C++ results expected. + - Exclude compiler generated functions from being reported. \ No newline at end of file From 3356b5e0163cd51f1bf71cf8a235170c8d1563bf Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Mon, 30 Sep 2024 07:56:50 -0700 Subject: [PATCH 17/62] Fix format --- .../FunctionWithNoReturningBranchShouldBeNoreturn.ql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql index 7383746d05..9769acdb7f 100644 --- a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql +++ b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql @@ -25,5 +25,4 @@ where not f.isFromUninstantiatedTemplate(_) and not f.isDeleted() and not f.isCompilerGenerated() -select f, - "The function " + f.getName() + " cannot return and should be declared as _Noreturn." +select f, "The function " + f.getName() + " cannot return and should be declared as _Noreturn." From 8ffbb1e41add56e47394e45abbaaefb65140aeea Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Mon, 30 Sep 2024 08:44:22 -0700 Subject: [PATCH 18/62] Update test expected message --- ...ionWithNoReturningBranchShouldBeNoreturn.expected | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected index fe275e9497..ecb77a477c 100644 --- a/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected +++ b/c/misra/test/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.expected @@ -1,6 +1,6 @@ -| test.c:7:6:7:21 | test_noreturn_f2 | The function test_noreturn_f2 cannot return and should be declared attribute _Noreturn. | -| test.c:18:6:18:21 | test_noreturn_f4 | The function test_noreturn_f4 cannot return and should be declared attribute _Noreturn. | -| test.c:47:6:47:21 | test_noreturn_f8 | The function test_noreturn_f8 cannot return and should be declared attribute _Noreturn. | -| test.c:63:6:63:22 | test_noreturn_f10 | The function test_noreturn_f10 cannot return and should be declared attribute _Noreturn. | -| test.c:97:6:97:22 | test_noreturn_f15 | The function test_noreturn_f15 cannot return and should be declared attribute _Noreturn. | -| test.c:101:6:101:22 | test_noreturn_f16 | The function test_noreturn_f16 cannot return and should be declared attribute _Noreturn. | +| test.c:7:6:7:21 | test_noreturn_f2 | The function test_noreturn_f2 cannot return and should be declared as _Noreturn. | +| test.c:18:6:18:21 | test_noreturn_f4 | The function test_noreturn_f4 cannot return and should be declared as _Noreturn. | +| test.c:47:6:47:21 | test_noreturn_f8 | The function test_noreturn_f8 cannot return and should be declared as _Noreturn. | +| test.c:63:6:63:22 | test_noreturn_f10 | The function test_noreturn_f10 cannot return and should be declared as _Noreturn. | +| test.c:97:6:97:22 | test_noreturn_f15 | The function test_noreturn_f15 cannot return and should be declared as _Noreturn. | +| test.c:101:6:101:22 | test_noreturn_f16 | The function test_noreturn_f16 cannot return and should be declared as _Noreturn. | From 2fbb70f5c0be55164213c1b54dca2ccc705a08c6 Mon Sep 17 00:00:00 2001 From: Luke Cartey <5377966+lcartey@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:28:12 +0100 Subject: [PATCH 19/62] Use v4 for upload-artifact --- .github/workflows/codeql_unit_tests.yml | 2 +- .github/workflows/standard_library_upgrade_tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql_unit_tests.yml b/.github/workflows/codeql_unit_tests.yml index a6488a728c..251e972a91 100644 --- a/.github/workflows/codeql_unit_tests.yml +++ b/.github/workflows/codeql_unit_tests.yml @@ -151,7 +151,7 @@ jobs: file.close() - name: Upload test results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.language }}-test-results-${{ runner.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }} path: | diff --git a/.github/workflows/standard_library_upgrade_tests.yml b/.github/workflows/standard_library_upgrade_tests.yml index 35717b7b4e..b6c3d38d87 100644 --- a/.github/workflows/standard_library_upgrade_tests.yml +++ b/.github/workflows/standard_library_upgrade_tests.yml @@ -143,7 +143,7 @@ jobs: }, test_summary_file) - name: Upload test results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: test-results-${{runner.os}}-${{matrix.codeql_cli}}-${{matrix.codeql_standard_library_ident}} path: | From 81fb797339d5a9ea216fe41731956e07d7847df4 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Wed, 2 Oct 2024 13:46:24 -0700 Subject: [PATCH 20/62] Set FunctionWithNoReturningBranch... to very-high precision --- .../RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql index 9769acdb7f..90cb1af7c2 100644 --- a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql +++ b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql @@ -3,7 +3,7 @@ * @name RULE-17-11: A function without a branch that returns shall be declared with _Noreturn * @description Functions which cannot return should be declared with _Noreturn. * @kind problem - * @precision high + * @precision very-high * @problem.severity recommendation * @tags external/misra/id/rule-17-11 * correctness From 71b4c250ffd667c447e0cb2247c932229e867d56 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Wed, 2 Oct 2024 13:54:25 -0700 Subject: [PATCH 21/62] Fix NoReturn.json package description precision 17-11 --- rule_packages/c/NoReturn.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rule_packages/c/NoReturn.json b/rule_packages/c/NoReturn.json index d06068f376..49cdb4c255 100644 --- a/rule_packages/c/NoReturn.json +++ b/rule_packages/c/NoReturn.json @@ -26,7 +26,7 @@ "description": "Functions which cannot return should be declared with _Noreturn.", "kind": "problem", "name": "A function without a branch that returns shall be declared with _Noreturn", - "precision": "high", + "precision": "very-high", "severity": "recommendation", "short_name": "FunctionWithNoReturningBranchShouldBeNoreturn", "tags": ["correctness"] From ce6709d26cd590513bf90256bd4cddc0f9e32903 Mon Sep 17 00:00:00 2001 From: Michael R Fairhurst Date: Wed, 18 Sep 2024 19:58:23 +0000 Subject: [PATCH 22/62] Fix #689, false negatives for A1-1-2 thinking -Wno-foo is compliant. The presence of -Wno-foo should not mark the compilation compliant with A1-1-2, nor should the presence of -Wfoo=0. Easily check for all -Wfoo=bar flags, that foo is not no-baz, and bar is not 0. Also check there is no -Wno-foo flag overruling it. Otherwise the query functionality remains the same. Add test cases for non-compliant scenarios -Wfoo=0 and -Wno-foo, and for the compliant scenario -Wall -Wno-foo. This will have some compatibility issues with PR #688, after one is merged the other will need some small updates before this can be merged. --- ...2024-09-18-handle-warning-suppresion-flags | 2 + .../CompilerWarningLevelNotInCompliance.ql | 51 ++++++++++++++++++- ...mpilerWarningLevelNotInCompliance.expected | 1 + .../CompilerWarningLevelNotInCompliance.qlref | 1 + .../Wformat=0-Wno-format-security.cpp | 2 + cpp/autosar/test/rules/A1-1-2.4/options.clang | 1 + cpp/autosar/test/rules/A1-1-2.4/options.gcc | 1 + cpp/autosar/test/rules/A1-1-2.4/options.qcc | 1 + ...mpilerWarningLevelNotInCompliance.expected | 1 + ...WarningLevelNotInCompliance.expected.clang | 0 ...erWarningLevelNotInCompliance.expected.gcc | 0 ...erWarningLevelNotInCompliance.expected.qcc | 1 + .../CompilerWarningLevelNotInCompliance.qlref | 1 + .../test/rules/A1-1-2.5/Wall-Wno-format.cpp | 14 +++++ cpp/autosar/test/rules/A1-1-2.5/options.clang | 1 + cpp/autosar/test/rules/A1-1-2.5/options.gcc | 1 + cpp/autosar/test/rules/A1-1-2.5/options.qcc | 1 + ...mpilerWarningLevelNotInCompliance.expected | 2 +- 18 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 change_notes/2024-09-18-handle-warning-suppresion-flags create mode 100644 cpp/autosar/test/rules/A1-1-2.4/CompilerWarningLevelNotInCompliance.expected create mode 100644 cpp/autosar/test/rules/A1-1-2.4/CompilerWarningLevelNotInCompliance.qlref create mode 100644 cpp/autosar/test/rules/A1-1-2.4/Wformat=0-Wno-format-security.cpp create mode 100644 cpp/autosar/test/rules/A1-1-2.4/options.clang create mode 100644 cpp/autosar/test/rules/A1-1-2.4/options.gcc create mode 100644 cpp/autosar/test/rules/A1-1-2.4/options.qcc create mode 100644 cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected create mode 100644 cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.clang create mode 100644 cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.gcc create mode 100644 cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.qcc create mode 100644 cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.qlref create mode 100644 cpp/autosar/test/rules/A1-1-2.5/Wall-Wno-format.cpp create mode 100644 cpp/autosar/test/rules/A1-1-2.5/options.clang create mode 100644 cpp/autosar/test/rules/A1-1-2.5/options.gcc create mode 100644 cpp/autosar/test/rules/A1-1-2.5/options.qcc diff --git a/change_notes/2024-09-18-handle-warning-suppresion-flags b/change_notes/2024-09-18-handle-warning-suppresion-flags new file mode 100644 index 0000000000..12bf30e937 --- /dev/null +++ b/change_notes/2024-09-18-handle-warning-suppresion-flags @@ -0,0 +1,2 @@ +- `A1-1-2` - `CompilerWarningLevelNotInCompliance.ql`: + - Fixes #689 false negatives where '-Wno-foo' was treated as enabling, rather than disabling warnings. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql b/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql index 60efab251a..55f67a9301 100644 --- a/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql +++ b/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql @@ -18,14 +18,61 @@ import cpp import codingstandards.cpp.autosar +predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@%") } + class CompilationWithNoWarnings extends Compilation { CompilationWithNoWarnings() { getAnArgument() = "-w" or - not getAnArgument().regexpMatch("-W[\\w=-]+") + not exists(EnableWarningFlag enableFlag | + this.getAnArgument() = enableFlag and + not exists(DisableWarningFlag disableFlag | + this.getAnArgument() = disableFlag and + enableFlag.getWarningType() = disableFlag.getWarningType() + ) + ) } } -predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@%") } +class CompilationArgument extends string { + Compilation compilation; + + CompilationArgument() { + this = compilation.getAnArgument() + } +} + +/** + * Compiler flags of type -Wfoo or -Wfoo=bar, which enables the `foo` warning. + */ +class EnableWarningFlag extends CompilationArgument { + string warningType; + + EnableWarningFlag() { + warningType = regexpCapture("^-W([\\w-]+)(=.*)?$", 1) + and not this instanceof DisableWarningFlag + } + + string getWarningType() { + result = warningType + } +} + +/** + * Compiler flags of type -Wno-foo or -Wfoo=0, which disables the `foo` warning + * and overrules -Wfoo. + */ +class DisableWarningFlag extends CompilationArgument { + string warningType; + + DisableWarningFlag() { + warningType = regexpCapture("^-Wno-([\\w-]+)", 1) or + warningType = regexpCapture("^-W([\\w-]+)=0", 1) + } + + string getWarningType() { + result = warningType + } +} from File f where diff --git a/cpp/autosar/test/rules/A1-1-2.4/CompilerWarningLevelNotInCompliance.expected b/cpp/autosar/test/rules/A1-1-2.4/CompilerWarningLevelNotInCompliance.expected new file mode 100644 index 0000000000..dd7f320be2 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.4/CompilerWarningLevelNotInCompliance.expected @@ -0,0 +1 @@ +| Wformat=0-Wno-format-security.cpp:0:0:0:0 | Wformat=0-Wno-format-security.cpp | No warning-level options were used in the compilation of 'Wformat=0-Wno-format-security.cpp'. | diff --git a/cpp/autosar/test/rules/A1-1-2.4/CompilerWarningLevelNotInCompliance.qlref b/cpp/autosar/test/rules/A1-1-2.4/CompilerWarningLevelNotInCompliance.qlref new file mode 100644 index 0000000000..30fb98b639 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.4/CompilerWarningLevelNotInCompliance.qlref @@ -0,0 +1 @@ +rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.4/Wformat=0-Wno-format-security.cpp b/cpp/autosar/test/rules/A1-1-2.4/Wformat=0-Wno-format-security.cpp new file mode 100644 index 0000000000..29523ad24e --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.4/Wformat=0-Wno-format-security.cpp @@ -0,0 +1,2 @@ +// semmle-extractor-options: --clang -std=c++14 -Wformat=0 -Wno-format-security +// NON_COMPLIANT \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.4/options.clang b/cpp/autosar/test/rules/A1-1-2.4/options.clang new file mode 100644 index 0000000000..4544f91ecb --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.4/options.clang @@ -0,0 +1 @@ +-Wformat=0 -Wno-format-security \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.4/options.gcc b/cpp/autosar/test/rules/A1-1-2.4/options.gcc new file mode 100644 index 0000000000..4544f91ecb --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.4/options.gcc @@ -0,0 +1 @@ +-Wformat=0 -Wno-format-security \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.4/options.qcc b/cpp/autosar/test/rules/A1-1-2.4/options.qcc new file mode 100644 index 0000000000..e28a2c3ac5 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.4/options.qcc @@ -0,0 +1 @@ +-Wno-format -Wno-format-security \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected b/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected new file mode 100644 index 0000000000..df69d21d5a --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected @@ -0,0 +1 @@ +| Wall-Wno-format.cpp:0:0:0:0 | Wall-Wno-format.cpp | No warning-level options were used in the compilation of 'Wall-Wno-format.cpp'. | \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.clang b/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.clang new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.gcc b/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.gcc new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.qcc b/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.qcc new file mode 100644 index 0000000000..c6354c2475 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.expected.qcc @@ -0,0 +1 @@ +| Wall-Wno-format.cpp:0:0:0:0 | Wall-Wno-format.cpp | No warning-level options were used in the compilation of 'Wall-Wno-format.cpp'. | diff --git a/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.qlref b/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.qlref new file mode 100644 index 0000000000..30fb98b639 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.5/CompilerWarningLevelNotInCompliance.qlref @@ -0,0 +1 @@ +rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.5/Wall-Wno-format.cpp b/cpp/autosar/test/rules/A1-1-2.5/Wall-Wno-format.cpp new file mode 100644 index 0000000000..93c4b98248 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.5/Wall-Wno-format.cpp @@ -0,0 +1,14 @@ +// semmle-extractor-options: --clang -std=c++14 -Wall -Wno-format +// COMPLIANT + +// NOTE: When tested with `codeql test run`, the test extractor provides `-w` +// which overrides `-Wcast-function-type` and causes this test case to be +// non-compliant. +// +// However, when tested with our compiler matrix tests, this test db is built +// via `codeql database create --command="..."`, and the `-w` flag will NOT be +// used. This means the `-Wcast-function-type` flag is active and the test case +// is compliant. +// +// Therefore, the .expected file for this test expects non-compliance, and the +// .expected.gcc and .expected.clang files expect this test to be compliant. diff --git a/cpp/autosar/test/rules/A1-1-2.5/options.clang b/cpp/autosar/test/rules/A1-1-2.5/options.clang new file mode 100644 index 0000000000..735817b680 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.5/options.clang @@ -0,0 +1 @@ +-Wall -Wno-format \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.5/options.gcc b/cpp/autosar/test/rules/A1-1-2.5/options.gcc new file mode 100644 index 0000000000..735817b680 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.5/options.gcc @@ -0,0 +1 @@ +-Wall -Wno-format \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2.5/options.qcc b/cpp/autosar/test/rules/A1-1-2.5/options.qcc new file mode 100644 index 0000000000..735817b680 --- /dev/null +++ b/cpp/autosar/test/rules/A1-1-2.5/options.qcc @@ -0,0 +1 @@ +-Wall -Wno-format \ No newline at end of file diff --git a/cpp/autosar/test/rules/A1-1-2/CompilerWarningLevelNotInCompliance.expected b/cpp/autosar/test/rules/A1-1-2/CompilerWarningLevelNotInCompliance.expected index 82ff1c0c36..ddc4e03f62 100644 --- a/cpp/autosar/test/rules/A1-1-2/CompilerWarningLevelNotInCompliance.expected +++ b/cpp/autosar/test/rules/A1-1-2/CompilerWarningLevelNotInCompliance.expected @@ -1 +1 @@ -| Wall.cpp:0:0:0:0 | Wall.cpp | No warning-level options were used in the compilation of 'Wall.cpp'. | \ No newline at end of file +| Wall.cpp:0:0:0:0 | Wall.cpp | No warning-level options were used in the compilation of 'Wall.cpp'. | From 20f790ac186614cd5054dfc5097c31f10b3719b7 Mon Sep 17 00:00:00 2001 From: Michael R Fairhurst Date: Wed, 18 Sep 2024 20:07:48 +0000 Subject: [PATCH 23/62] Query format --- .../CompilerWarningLevelNotInCompliance.ql | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql b/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql index 55f67a9301..dd51e31ed7 100644 --- a/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql +++ b/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql @@ -36,9 +36,7 @@ class CompilationWithNoWarnings extends Compilation { class CompilationArgument extends string { Compilation compilation; - CompilationArgument() { - this = compilation.getAnArgument() - } + CompilationArgument() { this = compilation.getAnArgument() } } /** @@ -48,13 +46,11 @@ class EnableWarningFlag extends CompilationArgument { string warningType; EnableWarningFlag() { - warningType = regexpCapture("^-W([\\w-]+)(=.*)?$", 1) - and not this instanceof DisableWarningFlag + warningType = regexpCapture("^-W([\\w-]+)(=.*)?$", 1) and + not this instanceof DisableWarningFlag } - string getWarningType() { - result = warningType - } + string getWarningType() { result = warningType } } /** @@ -69,9 +65,7 @@ class DisableWarningFlag extends CompilationArgument { warningType = regexpCapture("^-W([\\w-]+)=0", 1) } - string getWarningType() { - result = warningType - } + string getWarningType() { result = warningType } } from File f From 35c517beb317ea0ff94ee451af4c9a8b7c6b5a9d Mon Sep 17 00:00:00 2001 From: Michael R Fairhurst Date: Wed, 2 Oct 2024 21:33:44 +0000 Subject: [PATCH 24/62] query format again --- .../src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql b/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql index dd51e31ed7..1499191236 100644 --- a/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql +++ b/cpp/autosar/src/rules/A1-1-2/CompilerWarningLevelNotInCompliance.ql @@ -22,8 +22,9 @@ predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@% class CompilationWithNoWarnings extends Compilation { CompilationWithNoWarnings() { - getAnArgument() = "-w" or - not exists(EnableWarningFlag enableFlag | + getAnArgument() = "-w" + or + not exists(EnableWarningFlag enableFlag | this.getAnArgument() = enableFlag and not exists(DisableWarningFlag disableFlag | this.getAnArgument() = disableFlag and From 0e9758e04c0d2fe3256dbcb5ef7c7ec6d9f2a6f9 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Wed, 2 Oct 2024 22:38:20 +0100 Subject: [PATCH 25/62] Add tags to represent which MISRA C version the rule was introduced in --- .../PrecautionIncludeGuardsNotProvided.ql | 1 + .../StdLibDynamicMemoryAllocationUsed.ql | 1 + ...ageOfAssemblyLanguageShouldBeDocumented.ql | 1 + .../LanguageNotEncapsulatedAndIsolated.ql | 1 + .../SectionsOfCodeShallNotBeCommentedOut.ql | 1 + ...dentifiersInTheSameNameSpaceUnambiguous.ql | 1 + ...ainNumericalTypeUsedOverExplicitTypedef.ql | 1 + ...tWithNoPointerDereferenceShouldBeOpaque.ql | 1 + .../DIR-4-9/FunctionOverFunctionLikeMacro.ql | 1 + .../LanguageExtensionsShouldNotBeUsed.ql | 1 + .../RULE-1-3/OccurrenceOfUndefinedBehavior.ql | 1 + .../RULE-1-4/EmergentLanguageFeaturesUsed.ql | 1 + .../OperandsOfAnInappropriateEssentialType.ql | 1 + .../RULE-10-1/PointerTypeOnLogicalOperator.ql | 1 + ...dditionSubtractionOnEssentiallyCharType.ql | 1 + .../AssignmentOfIncompatibleEssentialType.ql | 1 + ...andsWithMismatchedEssentialTypeCategory.ql | 1 + .../InappropriateEssentialTypeCast.ql | 1 + .../AssignmentToWiderEssentialType.ql | 1 + ...ImplicitConversionOfCompositeExpression.ql | 1 + .../InappropriateCastOfCompositeExpression.ql | 1 + ...rsionBetweenFunctionPointerAndOtherType.ql | 1 + ...etweenIncompleteTypePointerAndOtherType.ql | 1 + ...weenObjectPointerAndDifferentObjectType.ql | 1 + ...ionBetweenPointerToObjectAndIntegerType.ql | 1 + ...ionFromPointerToVoidIntoPointerToObject.ql | 1 + ...stBetweenPointerToVoidAndArithmeticType.ql | 1 + ...nPointerToObjectAndNonIntArithmeticType.ql | 1 + ...CastRemovesConstOrVolatileQualification.ql | 1 + ...NullNotUsedAsIntegerNullPointerConstant.ql | 1 + ...plicitPrecedenceOfOperatorsInExpression.ql | 1 + .../RULE-12-1/UnenclosedSizeofOperand.ql | 1 + .../RightHandOperandOfAShiftRange.ql | 1 + .../RULE-12-3/CommaOperatorShouldNotBeUsed.ql | 1 + ...antUnsignedIntegerExpressionsWrapAround.ql | 1 + .../SizeofOperatorUsedOnArrayTypeParam.ql | 1 + ...alizerListsContainPersistentSideEffects.ql | 1 + .../rules/RULE-13-2/UnsequencedSideEffects.ql | 1 + .../SideEffectAndCrementInFullExpression.ql | 1 + ...ltOfAnAssignmentOperatorShouldNotBeUsed.ql | 1 + ...pressedSideEffectInLogicOperatorOperand.ql | 1 + .../RULE-13-6/SizeofOperandWithSideEffect.ql | 1 + .../RULE-14-1/LoopOverEssentiallyFloatType.ql | 1 + .../rules/RULE-14-2/ForLoopNotWellFormed.ql | 1 + .../RULE-14-3/ControllingExprInvariant.ql | 1 + .../rules/RULE-14-4/NonBooleanIfCondition.ql | 1 + .../RULE-14-4/NonBooleanIterationCondition.ql | 1 + .../src/rules/RULE-15-1/GotoStatementUsed.ql | 1 + .../RULE-15-2/GotoLabelLocationCondition.ql | 1 + .../RULE-15-3/GotoLabelBlockCondition.ql | 1 + .../rules/RULE-15-4/LoopIterationCondition.ql | 1 + .../RULE-15-5/FunctionReturnCondition.ql | 1 + .../rules/RULE-15-6/LoopCompoundCondition.ql | 1 + .../RULE-15-6/SelectionCompoundCondition.ql | 1 + .../RULE-15-6/SwitchCompoundCondition.ql | 1 + .../src/rules/RULE-15-7/IfElseEndCondition.ql | 1 + .../RULE-16-1/SwitchCaseStartCondition.ql | 1 + .../RULE-16-1/SwitchStmtNotWellFormed.ql | 1 + .../NestSwitchLabelInSwitchStatement.ql | 1 + .../BreakShallTerminateSwitchClause.ql | 1 + .../EverySwitchShallHaveDefaultLabel.ql | 1 + .../DefaultNotFirstOrLastOfSwitch.ql | 1 + .../RULE-16-6/SwitchClauseNumberCondition.ql | 1 + .../SwitchExpressionBoolCondition.ql | 1 + .../rules/RULE-17-1/FeaturesOfStdarghUsed.ql | 1 + .../RULE-17-2/RecursiveFunctionCondition.ql | 1 + .../RULE-17-3/FunctionDeclaredImplicitly.ql | 1 + .../NonVoidFunctionReturnCondition.ql | 1 + .../ArrayFunctionArgumentNumberOfElements.ql | 1 + .../src/rules/RULE-17-6/UseOfArrayStatic.ql | 1 + .../ValueReturnedByAFunctionNotUsed.ql | 1 + .../ModificationOfFunctionParameter.ql | 1 + ...erAndDerivedPointerMustAddressSameArray.ql | 1 + ...tionBetweenPointersMustAddressSameArray.ql | 1 + ...OperatorComparesPointerToDifferentArray.ql | 1 + ...dditionOrSubtractionOperatorsOnPointers.ql | 1 + ...TwoLevelsOfPointerNestingInDeclarations.ql | 1 + ...StorageObjectAddressCopiedToOtherObject.ql | 1 + .../RULE-18-7/FlexibleArrayMembersDeclared.ql | 1 + .../RULE-18-8/VariableLengthArrayTypesUsed.ql | 1 + .../ObjectAssignedToAnOverlappingObject.ql | 1 + .../ObjectCopiedToAnOverlappingObject.ql | 1 + .../RULE-19-2/UnionKeywordShouldNotBeUsed.ql | 1 + c/misra/src/rules/RULE-2-1/UnreachableCode.ql | 1 + c/misra/src/rules/RULE-2-2/DeadCode.ql | 1 + .../rules/RULE-2-3/UnusedTypeDeclarations.ql | 1 + .../rules/RULE-2-4/UnusedTagDeclaration.ql | 1 + .../rules/RULE-2-5/UnusedMacroDeclaration.ql | 1 + .../rules/RULE-2-6/UnusedLabelDeclaration.ql | 1 + c/misra/src/rules/RULE-2-7/UnusedParameter.ql | 1 + ...irectivesPrecededByDirectivesOrComments.ql | 1 + ...reprocessorHashOperatorsShouldNotBeUsed.ql | 1 + ...oreThanOneHashOperatorInMacroDefinition.ql | 1 + .../MacroParameterUsedAsHashOperand.ql | 1 + .../ForbiddenCharactersInHeaderFileName.ql | 1 + .../MacroDefinedWithTheSameNameAsKeyword.ql | 1 + .../rules/RULE-20-5/UndefShouldNotBeUsed.ql | 1 + ...tionLikeMacroArgsContainHashTokenCQuery.ql | 1 + ...ParameterNotEnclosedInParenthesesCQuery.ql | 1 + .../ControllingExpressionIfDirective.ql | 1 + ...IdentifiersUsedInPreprocessorExpression.ql | 1 + ...ndefUsedOnReservedIdentifierOrMacroName.ql | 1 + ...StandardLibraryTimeAndDateFunctionsUsed.ql | 1 + .../StandardHeaderFileTgmathhUsed.ql | 1 + .../ExceptionHandlingFeaturesOfFenvhUsed.ql | 1 + .../CtypeFunctionArgNotUnsignedCharOrEof.ql | 1 + ...emcmpUsedToCompareNullTerminatedStrings.ql | 1 + ...veMemcmpArgNotPointersToCompatibleTypes.ql | 1 + .../MemcmpOnInappropriateEssentialTypeArgs.ql | 1 + ...tringFunctionPointerArgumentOutOfBounds.ql | 1 + .../StringLibrarySizeArgumentOutOfBounds.ql | 1 + ...ReturnedByLocaleSettingUsedAsPtrToConst.ql | 1 + .../DoNotDeclareAReservedIdentifier.ql | 1 + .../CallToSetlocaleInvalidatesOldPointers.ql | 1 + ...llToSetlocaleInvalidatesOldPointersWarn.ql | 1 + .../rules/RULE-21-21/SystemOfStdlibhUsed.ql | 1 + ...emoryAllocDeallocFunctionsOfStdlibhUsed.ql | 1 + .../StandardHeaderFileUsedSetjmph.ql | 1 + .../StandardHeaderFileUsedSignalh.ql | 1 + ...StandardLibraryInputoutputFunctionsUsed.ql | 1 + .../AtofAtoiAtolAndAtollOfStdlibhUsed.ql | 1 + .../TerminationFunctionsOfStdlibhUsed.ql | 1 + .../TerminationMacrosOfStdlibhUsed.ql | 1 + .../RULE-21-9/BsearchAndQsortOfStdlibhUsed.ql | 1 + .../CloseFileHandleWhenNoLongerNeededMisra.ql | 1 + .../FreeMemoryWhenNoLongerNeededMisra.ql | 1 + ...TestErrnoRightAfterErrnoSettingFunction.ql | 1 + ...OnlyFreeMemoryAllocatedDynamicallyMisra.ql | 1 + ...leOpenForReadAndWriteOnDifferentStreams.ql | 1 + .../AttemptToWriteToAReadOnlyStream.ql | 1 + .../PointerToAFileObjectDereferenced.ql | 1 + .../rules/RULE-22-6/FileUsedAfterClosed.ql | 1 + ...allBeComparedWithUnmodifiedReturnValues.ql | 1 + .../RULE-22-8/ErrnoSetToZeroPriorToCall.ql | 1 + .../RULE-22-9/ErrnoSetToZeroAfterCall.ql | 1 + ...CharacterSequencesAndUsedWithinAComment.ql | 1 + .../RULE-3-2/LineSplicingUsedInComments.ql | 1 + ...HexadecimalEscapeSequencesNotTerminated.ql | 1 + .../ExternalIdentifiersNotDistinct.ql | 1 + ...ifiersDeclaredInTheSameScopeNotDistinct.ql | 1 + .../src/rules/RULE-5-3/IdentifierHidingC.ql | 1 + ...MacroIdentifierNotDistinctFromParameter.ql | 1 + .../RULE-5-4/MacroIdentifiersNotDistinct.ql | 1 + .../IdentifiersNotDistinctFromMacroNames.ql | 1 + .../rules/RULE-5-6/TypedefNameNotUnique.ql | 1 + .../src/rules/RULE-5-7/TagNameNotUnique.ql | 1 + ...IdentifiersWithExternalLinkageNotUnique.ql | 1 + ...IdentifiersWithInternalLinkageNotUnique.ql | 1 + ...hallOnlyBeDeclaredWithAnAppropriateType.ql | 1 + .../SingleBitNamedBitFieldsOfASignedType.ql | 1 + .../BitFieldDeclaredAsMemberOfAUnion.ql | 1 + .../src/rules/RULE-7-1/OctalConstantsUsed.ql | 1 + .../UOrUSuffixRepresentedInUnsignedType.ql | 1 + .../LowercaseCharacterLUsedInLiteralSuffix.ql | 1 + .../StringLiteralAssignedToNonConstChar.ql | 1 + .../rules/RULE-8-1/ExplicitlyDeclareTypes.ql | 1 + .../InlineFunctionNotDeclaredStaticStorage.ql | 1 + ...yExternalLinkageSizeExplicitlySpecified.ql | 1 + ...lueImplicitEnumerationConstantNotUnique.ql | 1 + ...interShouldPointToConstTypeWhenPossible.ql | 1 + .../RULE-8-14/RestrictTypeQualifierUsed.ql | 1 + .../FunctionTypesNotInPrototypeForm.ql | 1 + .../DeclarationsOfAFunctionSameNameAndType.ql | 1 + .../DeclarationsOfAnObjectSameNameAndType.ql | 1 + .../CompatibleDeclarationFunctionDefined.ql | 1 + .../CompatibleDeclarationObjectDefined.ql | 1 + ...nalObjectOrFunctionNotDeclaredInOneFile.ql | 1 + ...ntifierWithExternalLinkageOneDefinition.ql | 1 + .../ShouldNotBeDefinedWithExternalLinkage.ql | 1 + ...ngStaticSpecifierFunctionRedeclarationC.ql | 1 + ...singStaticSpecifierObjectRedeclarationC.ql | 1 + ...nnecessaryExposedIdentifierDeclarationC.ql | 1 + ...ctWithAutoStorageDurationReadBeforeInit.ql | 1 + ...rForAggregateOrUnionNotEnclosedInBraces.ql | 1 + ...nitializedArrayWithExplicitInitializers.ql | 1 + ...dInitializationOfAggregateObjectElement.ql | 1 + rule_packages/c/Banned.json | 54 ++++-- rule_packages/c/BitfieldTypes.json | 8 +- rule_packages/c/BitfieldTypes2.json | 5 +- rule_packages/c/Concurrency4.json | 5 +- rule_packages/c/Contracts1.json | 54 +++--- rule_packages/c/Contracts2.json | 9 +- rule_packages/c/Contracts3.json | 71 +++++--- rule_packages/c/Contracts4.json | 22 ++- rule_packages/c/Contracts5.json | 52 +++--- rule_packages/c/Contracts6.json | 14 +- rule_packages/c/Contracts7.json | 9 +- rule_packages/c/DeadCode.json | 21 ++- rule_packages/c/Declarations1.json | 172 +++++++++--------- rule_packages/c/Declarations2.json | 162 ++++++++--------- rule_packages/c/Declarations3.json | 15 +- rule_packages/c/Declarations4.json | 18 +- rule_packages/c/Declarations5.json | 15 +- rule_packages/c/Declarations6.json | 21 ++- rule_packages/c/Declarations7.json | 6 +- rule_packages/c/EssentialTypes.json | 36 ++-- rule_packages/c/IO1.json | 3 +- rule_packages/c/IO3.json | 12 +- rule_packages/c/IO4.json | 2 +- rule_packages/c/IntegerOverflow.json | 3 +- rule_packages/c/InvalidMemory1.json | 3 +- rule_packages/c/Language1.json | 3 +- rule_packages/c/Language2.json | 6 +- rule_packages/c/Language3.json | 6 +- rule_packages/c/Memory1.json | 11 +- rule_packages/c/Memory2.json | 9 +- rule_packages/c/Misc.json | 2 +- rule_packages/c/OutOfBounds.json | 6 +- rule_packages/c/Pointers1.json | 51 ++++-- rule_packages/c/Pointers2.json | 2 +- rule_packages/c/Preprocessor1.json | 15 +- rule_packages/c/Preprocessor2.json | 12 +- rule_packages/c/Preprocessor3.json | 39 ++-- rule_packages/c/Preprocessor4.json | 9 +- rule_packages/c/Preprocessor5.json | 3 +- rule_packages/c/Preprocessor6.json | 3 +- rule_packages/c/SideEffects1.json | 18 +- rule_packages/c/SideEffects2.json | 6 +- rule_packages/c/SideEffects3.json | 3 +- .../c/StandardLibraryFunctionTypes.json | 8 +- rule_packages/c/Statements1.json | 13 +- rule_packages/c/Statements2.json | 15 +- rule_packages/c/Statements3.json | 21 ++- rule_packages/c/Statements4.json | 9 +- rule_packages/c/Statements5.json | 11 +- rule_packages/c/Statements6.json | 3 +- rule_packages/c/Static.json | 3 +- rule_packages/c/Syntax.json | 21 ++- rule_packages/c/Types1.json | 14 +- 229 files changed, 845 insertions(+), 445 deletions(-) diff --git a/c/misra/src/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.ql b/c/misra/src/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.ql index 58ec5c80a9..338437b5b2 100644 --- a/c/misra/src/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.ql +++ b/c/misra/src/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.ql @@ -10,6 +10,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.ql b/c/misra/src/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.ql index dc1e21c97a..5c70bec761 100644 --- a/c/misra/src/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.ql +++ b/c/misra/src/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.ql @@ -11,6 +11,7 @@ * security * correctness * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql b/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql index 9503024671..1afd57913e 100644 --- a/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql +++ b/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/dir-4-2 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/DIR-4-3/LanguageNotEncapsulatedAndIsolated.ql b/c/misra/src/rules/DIR-4-3/LanguageNotEncapsulatedAndIsolated.ql index fb9f00e9c4..698cbabf01 100644 --- a/c/misra/src/rules/DIR-4-3/LanguageNotEncapsulatedAndIsolated.ql +++ b/c/misra/src/rules/DIR-4-3/LanguageNotEncapsulatedAndIsolated.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/dir-4-3 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.ql b/c/misra/src/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.ql index d0af758699..272a411f0e 100644 --- a/c/misra/src/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.ql +++ b/c/misra/src/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.ql @@ -9,6 +9,7 @@ * maintainability * readability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/DIR-4-5/IdentifiersInTheSameNameSpaceUnambiguous.ql b/c/misra/src/rules/DIR-4-5/IdentifiersInTheSameNameSpaceUnambiguous.ql index ced5bce28f..5dd78fc340 100644 --- a/c/misra/src/rules/DIR-4-5/IdentifiersInTheSameNameSpaceUnambiguous.ql +++ b/c/misra/src/rules/DIR-4-5/IdentifiersInTheSameNameSpaceUnambiguous.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/dir-4-5 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/DIR-4-6/PlainNumericalTypeUsedOverExplicitTypedef.ql b/c/misra/src/rules/DIR-4-6/PlainNumericalTypeUsedOverExplicitTypedef.ql index c3ea6dfdbd..3891d8c99f 100644 --- a/c/misra/src/rules/DIR-4-6/PlainNumericalTypeUsedOverExplicitTypedef.ql +++ b/c/misra/src/rules/DIR-4-6/PlainNumericalTypeUsedOverExplicitTypedef.ql @@ -7,6 +7,7 @@ * @precision high * @problem.severity error * @tags external/misra/id/dir-4-6 + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql b/c/misra/src/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql index 56f2dd785d..b32a0a4aee 100644 --- a/c/misra/src/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql +++ b/c/misra/src/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/dir-4-8 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql b/c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql index 3d8a51f219..582715e34f 100644 --- a/c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql +++ b/c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql @@ -10,6 +10,7 @@ * external/misra/audit * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql index f38e41a1b6..9d1f27597f 100644 --- a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-1-2 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-1-3/OccurrenceOfUndefinedBehavior.ql b/c/misra/src/rules/RULE-1-3/OccurrenceOfUndefinedBehavior.ql index f6b295bd32..53f72e6bee 100644 --- a/c/misra/src/rules/RULE-1-3/OccurrenceOfUndefinedBehavior.ql +++ b/c/misra/src/rules/RULE-1-3/OccurrenceOfUndefinedBehavior.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-1-3 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql b/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql index 56ab349a11..a413b1c29a 100644 --- a/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql +++ b/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-1-4 * maintainability * readability + * external/misra/c/2012/amendment2 * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql b/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql index 5c39f89003..10612f3378 100644 --- a/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql +++ b/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-10-1 * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-10-1/PointerTypeOnLogicalOperator.ql b/c/misra/src/rules/RULE-10-1/PointerTypeOnLogicalOperator.ql index 21bfdcb2be..b17f3710d5 100644 --- a/c/misra/src/rules/RULE-10-1/PointerTypeOnLogicalOperator.ql +++ b/c/misra/src/rules/RULE-10-1/PointerTypeOnLogicalOperator.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-10-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-10-2/AdditionSubtractionOnEssentiallyCharType.ql b/c/misra/src/rules/RULE-10-2/AdditionSubtractionOnEssentiallyCharType.ql index ad0c630e23..750e589a1c 100644 --- a/c/misra/src/rules/RULE-10-2/AdditionSubtractionOnEssentiallyCharType.ql +++ b/c/misra/src/rules/RULE-10-2/AdditionSubtractionOnEssentiallyCharType.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-10-2 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-10-3/AssignmentOfIncompatibleEssentialType.ql b/c/misra/src/rules/RULE-10-3/AssignmentOfIncompatibleEssentialType.ql index 353f6a9c8d..af120fb13d 100644 --- a/c/misra/src/rules/RULE-10-3/AssignmentOfIncompatibleEssentialType.ql +++ b/c/misra/src/rules/RULE-10-3/AssignmentOfIncompatibleEssentialType.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-10-3 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-10-4/OperandsWithMismatchedEssentialTypeCategory.ql b/c/misra/src/rules/RULE-10-4/OperandsWithMismatchedEssentialTypeCategory.ql index d5ef8b6d26..cc4c860d7d 100644 --- a/c/misra/src/rules/RULE-10-4/OperandsWithMismatchedEssentialTypeCategory.ql +++ b/c/misra/src/rules/RULE-10-4/OperandsWithMismatchedEssentialTypeCategory.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-10-4 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-10-5/InappropriateEssentialTypeCast.ql b/c/misra/src/rules/RULE-10-5/InappropriateEssentialTypeCast.ql index 1ff8374e97..f782a16597 100644 --- a/c/misra/src/rules/RULE-10-5/InappropriateEssentialTypeCast.ql +++ b/c/misra/src/rules/RULE-10-5/InappropriateEssentialTypeCast.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-10-5 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-10-6/AssignmentToWiderEssentialType.ql b/c/misra/src/rules/RULE-10-6/AssignmentToWiderEssentialType.ql index 09e731ba71..8927e8570a 100644 --- a/c/misra/src/rules/RULE-10-6/AssignmentToWiderEssentialType.ql +++ b/c/misra/src/rules/RULE-10-6/AssignmentToWiderEssentialType.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-10-6 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql b/c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql index 1cf20378fa..b330bca00a 100644 --- a/c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql +++ b/c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-10-7 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-10-8/InappropriateCastOfCompositeExpression.ql b/c/misra/src/rules/RULE-10-8/InappropriateCastOfCompositeExpression.ql index 8e58ded416..162ba4439c 100644 --- a/c/misra/src/rules/RULE-10-8/InappropriateCastOfCompositeExpression.ql +++ b/c/misra/src/rules/RULE-10-8/InappropriateCastOfCompositeExpression.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-10-8 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-11-1/ConversionBetweenFunctionPointerAndOtherType.ql b/c/misra/src/rules/RULE-11-1/ConversionBetweenFunctionPointerAndOtherType.ql index acb5480e4f..36157e130e 100644 --- a/c/misra/src/rules/RULE-11-1/ConversionBetweenFunctionPointerAndOtherType.ql +++ b/c/misra/src/rules/RULE-11-1/ConversionBetweenFunctionPointerAndOtherType.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-11-2/ConversionBetweenIncompleteTypePointerAndOtherType.ql b/c/misra/src/rules/RULE-11-2/ConversionBetweenIncompleteTypePointerAndOtherType.ql index 43ee303415..6c552b0f39 100644 --- a/c/misra/src/rules/RULE-11-2/ConversionBetweenIncompleteTypePointerAndOtherType.ql +++ b/c/misra/src/rules/RULE-11-2/ConversionBetweenIncompleteTypePointerAndOtherType.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-2 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-11-3/CastBetweenObjectPointerAndDifferentObjectType.ql b/c/misra/src/rules/RULE-11-3/CastBetweenObjectPointerAndDifferentObjectType.ql index 59674e11ac..8292bd3b6f 100644 --- a/c/misra/src/rules/RULE-11-3/CastBetweenObjectPointerAndDifferentObjectType.ql +++ b/c/misra/src/rules/RULE-11-3/CastBetweenObjectPointerAndDifferentObjectType.ql @@ -9,6 +9,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-3 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-11-4/ConversionBetweenPointerToObjectAndIntegerType.ql b/c/misra/src/rules/RULE-11-4/ConversionBetweenPointerToObjectAndIntegerType.ql index aaa64fc3c0..8877d04323 100644 --- a/c/misra/src/rules/RULE-11-4/ConversionBetweenPointerToObjectAndIntegerType.ql +++ b/c/misra/src/rules/RULE-11-4/ConversionBetweenPointerToObjectAndIntegerType.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-4 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-11-5/ConversionFromPointerToVoidIntoPointerToObject.ql b/c/misra/src/rules/RULE-11-5/ConversionFromPointerToVoidIntoPointerToObject.ql index 69419e13cd..bdaebcbf54 100644 --- a/c/misra/src/rules/RULE-11-5/ConversionFromPointerToVoidIntoPointerToObject.ql +++ b/c/misra/src/rules/RULE-11-5/ConversionFromPointerToVoidIntoPointerToObject.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-5 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-11-6/CastBetweenPointerToVoidAndArithmeticType.ql b/c/misra/src/rules/RULE-11-6/CastBetweenPointerToVoidAndArithmeticType.ql index de75e9d37a..cc0adf0517 100644 --- a/c/misra/src/rules/RULE-11-6/CastBetweenPointerToVoidAndArithmeticType.ql +++ b/c/misra/src/rules/RULE-11-6/CastBetweenPointerToVoidAndArithmeticType.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-6 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-11-7/CastBetweenPointerToObjectAndNonIntArithmeticType.ql b/c/misra/src/rules/RULE-11-7/CastBetweenPointerToObjectAndNonIntArithmeticType.ql index f898998d32..e499ea6485 100644 --- a/c/misra/src/rules/RULE-11-7/CastBetweenPointerToObjectAndNonIntArithmeticType.ql +++ b/c/misra/src/rules/RULE-11-7/CastBetweenPointerToObjectAndNonIntArithmeticType.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-7 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-11-8/CastRemovesConstOrVolatileQualification.ql b/c/misra/src/rules/RULE-11-8/CastRemovesConstOrVolatileQualification.ql index 17b0df1a0e..17b12aaf99 100644 --- a/c/misra/src/rules/RULE-11-8/CastRemovesConstOrVolatileQualification.ql +++ b/c/misra/src/rules/RULE-11-8/CastRemovesConstOrVolatileQualification.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-8 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-11-9/MacroNullNotUsedAsIntegerNullPointerConstant.ql b/c/misra/src/rules/RULE-11-9/MacroNullNotUsedAsIntegerNullPointerConstant.ql index a5c34fb747..cb18ed0d1d 100644 --- a/c/misra/src/rules/RULE-11-9/MacroNullNotUsedAsIntegerNullPointerConstant.ql +++ b/c/misra/src/rules/RULE-11-9/MacroNullNotUsedAsIntegerNullPointerConstant.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-11-9 * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-12-1/ImplicitPrecedenceOfOperatorsInExpression.ql b/c/misra/src/rules/RULE-12-1/ImplicitPrecedenceOfOperatorsInExpression.ql index 005fffa32d..134068463c 100644 --- a/c/misra/src/rules/RULE-12-1/ImplicitPrecedenceOfOperatorsInExpression.ql +++ b/c/misra/src/rules/RULE-12-1/ImplicitPrecedenceOfOperatorsInExpression.ql @@ -9,6 +9,7 @@ * @problem.severity warning * @tags external/misra/id/rule-12-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-12-1/UnenclosedSizeofOperand.ql b/c/misra/src/rules/RULE-12-1/UnenclosedSizeofOperand.ql index 8975e7dff7..0081de320c 100644 --- a/c/misra/src/rules/RULE-12-1/UnenclosedSizeofOperand.ql +++ b/c/misra/src/rules/RULE-12-1/UnenclosedSizeofOperand.ql @@ -9,6 +9,7 @@ * @problem.severity warning * @tags external/misra/id/rule-12-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-12-2/RightHandOperandOfAShiftRange.ql b/c/misra/src/rules/RULE-12-2/RightHandOperandOfAShiftRange.ql index bd77bdacd2..da7a0f181e 100644 --- a/c/misra/src/rules/RULE-12-2/RightHandOperandOfAShiftRange.ql +++ b/c/misra/src/rules/RULE-12-2/RightHandOperandOfAShiftRange.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-12-2 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-12-3/CommaOperatorShouldNotBeUsed.ql b/c/misra/src/rules/RULE-12-3/CommaOperatorShouldNotBeUsed.ql index ec782d84f5..bccb382804 100644 --- a/c/misra/src/rules/RULE-12-3/CommaOperatorShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-12-3/CommaOperatorShouldNotBeUsed.ql @@ -7,6 +7,7 @@ * @problem.severity recommendation * @tags external/misra/id/rule-12-3 * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-12-4/ConstantUnsignedIntegerExpressionsWrapAround.ql b/c/misra/src/rules/RULE-12-4/ConstantUnsignedIntegerExpressionsWrapAround.ql index 5009ef292d..1ebbf184bb 100644 --- a/c/misra/src/rules/RULE-12-4/ConstantUnsignedIntegerExpressionsWrapAround.ql +++ b/c/misra/src/rules/RULE-12-4/ConstantUnsignedIntegerExpressionsWrapAround.ql @@ -14,6 +14,7 @@ * @tags external/misra/id/rule-12-4 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-12-5/SizeofOperatorUsedOnArrayTypeParam.ql b/c/misra/src/rules/RULE-12-5/SizeofOperatorUsedOnArrayTypeParam.ql index 3eed267198..2e080419e1 100644 --- a/c/misra/src/rules/RULE-12-5/SizeofOperatorUsedOnArrayTypeParam.ql +++ b/c/misra/src/rules/RULE-12-5/SizeofOperatorUsedOnArrayTypeParam.ql @@ -7,6 +7,7 @@ * @precision very-high * @problem.severity error * @tags external/misra/id/rule-12-5 + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-13-1/InitializerListsContainPersistentSideEffects.ql b/c/misra/src/rules/RULE-13-1/InitializerListsContainPersistentSideEffects.ql index 3cce2bb825..69ecbede58 100644 --- a/c/misra/src/rules/RULE-13-1/InitializerListsContainPersistentSideEffects.ql +++ b/c/misra/src/rules/RULE-13-1/InitializerListsContainPersistentSideEffects.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-13-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-13-2/UnsequencedSideEffects.ql b/c/misra/src/rules/RULE-13-2/UnsequencedSideEffects.ql index 2497e5d4a3..90b0315e88 100644 --- a/c/misra/src/rules/RULE-13-2/UnsequencedSideEffects.ql +++ b/c/misra/src/rules/RULE-13-2/UnsequencedSideEffects.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-13-2 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-13-3/SideEffectAndCrementInFullExpression.ql b/c/misra/src/rules/RULE-13-3/SideEffectAndCrementInFullExpression.ql index 3dd03120c8..173827e04e 100644 --- a/c/misra/src/rules/RULE-13-3/SideEffectAndCrementInFullExpression.ql +++ b/c/misra/src/rules/RULE-13-3/SideEffectAndCrementInFullExpression.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-13-3 * readability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql b/c/misra/src/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql index 69a5d57f25..c840947b1f 100644 --- a/c/misra/src/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-13-4 * correctness * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-13-5/PossibleSuppressedSideEffectInLogicOperatorOperand.ql b/c/misra/src/rules/RULE-13-5/PossibleSuppressedSideEffectInLogicOperatorOperand.ql index 90faf9ec23..9a5b7b2b7b 100644 --- a/c/misra/src/rules/RULE-13-5/PossibleSuppressedSideEffectInLogicOperatorOperand.ql +++ b/c/misra/src/rules/RULE-13-5/PossibleSuppressedSideEffectInLogicOperatorOperand.ql @@ -9,6 +9,7 @@ * @problem.severity error * @tags external/misra/id/rule-13-5 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-13-6/SizeofOperandWithSideEffect.ql b/c/misra/src/rules/RULE-13-6/SizeofOperandWithSideEffect.ql index 10317b1169..ec1551c2a6 100644 --- a/c/misra/src/rules/RULE-13-6/SizeofOperandWithSideEffect.ql +++ b/c/misra/src/rules/RULE-13-6/SizeofOperandWithSideEffect.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-13-6 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-14-1/LoopOverEssentiallyFloatType.ql b/c/misra/src/rules/RULE-14-1/LoopOverEssentiallyFloatType.ql index 6a0f772f61..83d91dac63 100644 --- a/c/misra/src/rules/RULE-14-1/LoopOverEssentiallyFloatType.ql +++ b/c/misra/src/rules/RULE-14-1/LoopOverEssentiallyFloatType.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-14-1 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-14-2/ForLoopNotWellFormed.ql b/c/misra/src/rules/RULE-14-2/ForLoopNotWellFormed.ql index 106bd9b5c6..7b3dc3c8dc 100644 --- a/c/misra/src/rules/RULE-14-2/ForLoopNotWellFormed.ql +++ b/c/misra/src/rules/RULE-14-2/ForLoopNotWellFormed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-14-2 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-14-3/ControllingExprInvariant.ql b/c/misra/src/rules/RULE-14-3/ControllingExprInvariant.ql index eb8e9ede82..1bd2708750 100644 --- a/c/misra/src/rules/RULE-14-3/ControllingExprInvariant.ql +++ b/c/misra/src/rules/RULE-14-3/ControllingExprInvariant.ql @@ -10,6 +10,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-14-4/NonBooleanIfCondition.ql b/c/misra/src/rules/RULE-14-4/NonBooleanIfCondition.ql index 87d9d31512..f9a24d9492 100644 --- a/c/misra/src/rules/RULE-14-4/NonBooleanIfCondition.ql +++ b/c/misra/src/rules/RULE-14-4/NonBooleanIfCondition.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-14-4 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-14-4/NonBooleanIterationCondition.ql b/c/misra/src/rules/RULE-14-4/NonBooleanIterationCondition.ql index b2644a7a92..8418993db2 100644 --- a/c/misra/src/rules/RULE-14-4/NonBooleanIterationCondition.ql +++ b/c/misra/src/rules/RULE-14-4/NonBooleanIterationCondition.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-14-4 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-15-1/GotoStatementUsed.ql b/c/misra/src/rules/RULE-15-1/GotoStatementUsed.ql index d1c9aadadd..84c7dbd408 100644 --- a/c/misra/src/rules/RULE-15-1/GotoStatementUsed.ql +++ b/c/misra/src/rules/RULE-15-1/GotoStatementUsed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-15-1 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-15-2/GotoLabelLocationCondition.ql b/c/misra/src/rules/RULE-15-2/GotoLabelLocationCondition.ql index d12521dd7e..623fb9baed 100644 --- a/c/misra/src/rules/RULE-15-2/GotoLabelLocationCondition.ql +++ b/c/misra/src/rules/RULE-15-2/GotoLabelLocationCondition.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-15-2 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql b/c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql index 1f9f066f53..a88f3170de 100644 --- a/c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql +++ b/c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-15-3 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-15-4/LoopIterationCondition.ql b/c/misra/src/rules/RULE-15-4/LoopIterationCondition.ql index ed541a68d0..b172a2c1ea 100644 --- a/c/misra/src/rules/RULE-15-4/LoopIterationCondition.ql +++ b/c/misra/src/rules/RULE-15-4/LoopIterationCondition.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-15-4 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-15-5/FunctionReturnCondition.ql b/c/misra/src/rules/RULE-15-5/FunctionReturnCondition.ql index 2fb5ad9d65..8e777d7332 100644 --- a/c/misra/src/rules/RULE-15-5/FunctionReturnCondition.ql +++ b/c/misra/src/rules/RULE-15-5/FunctionReturnCondition.ql @@ -9,6 +9,7 @@ * maintainability * readability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-15-6/LoopCompoundCondition.ql b/c/misra/src/rules/RULE-15-6/LoopCompoundCondition.ql index a3e30ec345..9cc5bf9dda 100644 --- a/c/misra/src/rules/RULE-15-6/LoopCompoundCondition.ql +++ b/c/misra/src/rules/RULE-15-6/LoopCompoundCondition.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-15-6 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-15-6/SelectionCompoundCondition.ql b/c/misra/src/rules/RULE-15-6/SelectionCompoundCondition.ql index d181ca2d1c..f84c142414 100644 --- a/c/misra/src/rules/RULE-15-6/SelectionCompoundCondition.ql +++ b/c/misra/src/rules/RULE-15-6/SelectionCompoundCondition.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-15-6 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-15-6/SwitchCompoundCondition.ql b/c/misra/src/rules/RULE-15-6/SwitchCompoundCondition.ql index 837bfb12c1..1d446f323f 100644 --- a/c/misra/src/rules/RULE-15-6/SwitchCompoundCondition.ql +++ b/c/misra/src/rules/RULE-15-6/SwitchCompoundCondition.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-15-6 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-15-7/IfElseEndCondition.ql b/c/misra/src/rules/RULE-15-7/IfElseEndCondition.ql index f3992d26f5..ee06f484fe 100644 --- a/c/misra/src/rules/RULE-15-7/IfElseEndCondition.ql +++ b/c/misra/src/rules/RULE-15-7/IfElseEndCondition.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-15-7 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-16-1/SwitchCaseStartCondition.ql b/c/misra/src/rules/RULE-16-1/SwitchCaseStartCondition.ql index e30ac1bd7b..4ceca23d8f 100644 --- a/c/misra/src/rules/RULE-16-1/SwitchCaseStartCondition.ql +++ b/c/misra/src/rules/RULE-16-1/SwitchCaseStartCondition.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-16-1 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-16-1/SwitchStmtNotWellFormed.ql b/c/misra/src/rules/RULE-16-1/SwitchStmtNotWellFormed.ql index 9da9242a78..644994562a 100644 --- a/c/misra/src/rules/RULE-16-1/SwitchStmtNotWellFormed.ql +++ b/c/misra/src/rules/RULE-16-1/SwitchStmtNotWellFormed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-16-1 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-16-2/NestSwitchLabelInSwitchStatement.ql b/c/misra/src/rules/RULE-16-2/NestSwitchLabelInSwitchStatement.ql index df4b6fc93a..45ad0519bb 100644 --- a/c/misra/src/rules/RULE-16-2/NestSwitchLabelInSwitchStatement.ql +++ b/c/misra/src/rules/RULE-16-2/NestSwitchLabelInSwitchStatement.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-16-2 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-16-3/BreakShallTerminateSwitchClause.ql b/c/misra/src/rules/RULE-16-3/BreakShallTerminateSwitchClause.ql index e62fe8c8d4..5ff30b53e0 100644 --- a/c/misra/src/rules/RULE-16-3/BreakShallTerminateSwitchClause.ql +++ b/c/misra/src/rules/RULE-16-3/BreakShallTerminateSwitchClause.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-16-3 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-16-4/EverySwitchShallHaveDefaultLabel.ql b/c/misra/src/rules/RULE-16-4/EverySwitchShallHaveDefaultLabel.ql index a5d7c3cf2c..441e30b7e7 100644 --- a/c/misra/src/rules/RULE-16-4/EverySwitchShallHaveDefaultLabel.ql +++ b/c/misra/src/rules/RULE-16-4/EverySwitchShallHaveDefaultLabel.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-16-4 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-16-5/DefaultNotFirstOrLastOfSwitch.ql b/c/misra/src/rules/RULE-16-5/DefaultNotFirstOrLastOfSwitch.ql index f86e242ee3..5a93477b9a 100644 --- a/c/misra/src/rules/RULE-16-5/DefaultNotFirstOrLastOfSwitch.ql +++ b/c/misra/src/rules/RULE-16-5/DefaultNotFirstOrLastOfSwitch.ql @@ -6,6 +6,7 @@ * @precision very-high * @problem.severity recommendation * @tags external/misra/id/rule-16-5 + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-16-6/SwitchClauseNumberCondition.ql b/c/misra/src/rules/RULE-16-6/SwitchClauseNumberCondition.ql index 8ddb2e49b2..0259f8023d 100644 --- a/c/misra/src/rules/RULE-16-6/SwitchClauseNumberCondition.ql +++ b/c/misra/src/rules/RULE-16-6/SwitchClauseNumberCondition.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-16-6 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-16-7/SwitchExpressionBoolCondition.ql b/c/misra/src/rules/RULE-16-7/SwitchExpressionBoolCondition.ql index 9aeb50d26e..06be288e2c 100644 --- a/c/misra/src/rules/RULE-16-7/SwitchExpressionBoolCondition.ql +++ b/c/misra/src/rules/RULE-16-7/SwitchExpressionBoolCondition.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-16-7 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-17-1/FeaturesOfStdarghUsed.ql b/c/misra/src/rules/RULE-17-1/FeaturesOfStdarghUsed.ql index 1cde8b98f2..ddccb58ad1 100644 --- a/c/misra/src/rules/RULE-17-1/FeaturesOfStdarghUsed.ql +++ b/c/misra/src/rules/RULE-17-1/FeaturesOfStdarghUsed.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-17-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-17-2/RecursiveFunctionCondition.ql b/c/misra/src/rules/RULE-17-2/RecursiveFunctionCondition.ql index b6f13c4d1f..c7cb818119 100644 --- a/c/misra/src/rules/RULE-17-2/RecursiveFunctionCondition.ql +++ b/c/misra/src/rules/RULE-17-2/RecursiveFunctionCondition.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-17-2 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-17-3/FunctionDeclaredImplicitly.ql b/c/misra/src/rules/RULE-17-3/FunctionDeclaredImplicitly.ql index 304d0a9bf6..af6c9bccad 100644 --- a/c/misra/src/rules/RULE-17-3/FunctionDeclaredImplicitly.ql +++ b/c/misra/src/rules/RULE-17-3/FunctionDeclaredImplicitly.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-17-3 * correctness * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-17-4/NonVoidFunctionReturnCondition.ql b/c/misra/src/rules/RULE-17-4/NonVoidFunctionReturnCondition.ql index 24329e5ab5..1529a403c9 100644 --- a/c/misra/src/rules/RULE-17-4/NonVoidFunctionReturnCondition.ql +++ b/c/misra/src/rules/RULE-17-4/NonVoidFunctionReturnCondition.ql @@ -10,6 +10,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-17-5/ArrayFunctionArgumentNumberOfElements.ql b/c/misra/src/rules/RULE-17-5/ArrayFunctionArgumentNumberOfElements.ql index 208e8153d6..bb29be50ac 100644 --- a/c/misra/src/rules/RULE-17-5/ArrayFunctionArgumentNumberOfElements.ql +++ b/c/misra/src/rules/RULE-17-5/ArrayFunctionArgumentNumberOfElements.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-17-5 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-17-6/UseOfArrayStatic.ql b/c/misra/src/rules/RULE-17-6/UseOfArrayStatic.ql index 876321c455..0a1232b6ad 100644 --- a/c/misra/src/rules/RULE-17-6/UseOfArrayStatic.ql +++ b/c/misra/src/rules/RULE-17-6/UseOfArrayStatic.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-17-6 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-17-7/ValueReturnedByAFunctionNotUsed.ql b/c/misra/src/rules/RULE-17-7/ValueReturnedByAFunctionNotUsed.ql index 02d0a54ec1..42b0d7a2e2 100644 --- a/c/misra/src/rules/RULE-17-7/ValueReturnedByAFunctionNotUsed.ql +++ b/c/misra/src/rules/RULE-17-7/ValueReturnedByAFunctionNotUsed.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-17-7 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-17-8/ModificationOfFunctionParameter.ql b/c/misra/src/rules/RULE-17-8/ModificationOfFunctionParameter.ql index 6867455a45..95cddb57d3 100644 --- a/c/misra/src/rules/RULE-17-8/ModificationOfFunctionParameter.ql +++ b/c/misra/src/rules/RULE-17-8/ModificationOfFunctionParameter.ql @@ -9,6 +9,7 @@ * @problem.severity warning * @tags external/misra/id/rule-17-8 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-18-1/PointerAndDerivedPointerMustAddressSameArray.ql b/c/misra/src/rules/RULE-18-1/PointerAndDerivedPointerMustAddressSameArray.ql index f17d596ead..c8944bd30d 100644 --- a/c/misra/src/rules/RULE-18-1/PointerAndDerivedPointerMustAddressSameArray.ql +++ b/c/misra/src/rules/RULE-18-1/PointerAndDerivedPointerMustAddressSameArray.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-18-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-18-2/SubtractionBetweenPointersMustAddressSameArray.ql b/c/misra/src/rules/RULE-18-2/SubtractionBetweenPointersMustAddressSameArray.ql index b6fbb31f1c..ec3a30d5ba 100644 --- a/c/misra/src/rules/RULE-18-2/SubtractionBetweenPointersMustAddressSameArray.ql +++ b/c/misra/src/rules/RULE-18-2/SubtractionBetweenPointersMustAddressSameArray.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-18-2 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-18-3/RelationalOperatorComparesPointerToDifferentArray.ql b/c/misra/src/rules/RULE-18-3/RelationalOperatorComparesPointerToDifferentArray.ql index d7785a2d0e..4624cea616 100644 --- a/c/misra/src/rules/RULE-18-3/RelationalOperatorComparesPointerToDifferentArray.ql +++ b/c/misra/src/rules/RULE-18-3/RelationalOperatorComparesPointerToDifferentArray.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-18-3 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-18-4/DoNotUseAdditionOrSubtractionOperatorsOnPointers.ql b/c/misra/src/rules/RULE-18-4/DoNotUseAdditionOrSubtractionOperatorsOnPointers.ql index a5f8a85ff1..a1a1ad367b 100644 --- a/c/misra/src/rules/RULE-18-4/DoNotUseAdditionOrSubtractionOperatorsOnPointers.ql +++ b/c/misra/src/rules/RULE-18-4/DoNotUseAdditionOrSubtractionOperatorsOnPointers.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-18-4 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-18-5/NoMoreThanTwoLevelsOfPointerNestingInDeclarations.ql b/c/misra/src/rules/RULE-18-5/NoMoreThanTwoLevelsOfPointerNestingInDeclarations.ql index 7a847acbfa..f467c41804 100644 --- a/c/misra/src/rules/RULE-18-5/NoMoreThanTwoLevelsOfPointerNestingInDeclarations.ql +++ b/c/misra/src/rules/RULE-18-5/NoMoreThanTwoLevelsOfPointerNestingInDeclarations.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-18-5 * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-18-6/AutomaticStorageObjectAddressCopiedToOtherObject.ql b/c/misra/src/rules/RULE-18-6/AutomaticStorageObjectAddressCopiedToOtherObject.ql index 6d947efb16..efbc8d1334 100644 --- a/c/misra/src/rules/RULE-18-6/AutomaticStorageObjectAddressCopiedToOtherObject.ql +++ b/c/misra/src/rules/RULE-18-6/AutomaticStorageObjectAddressCopiedToOtherObject.ql @@ -9,6 +9,7 @@ * @problem.severity error * @tags external/misra/id/rule-18-6 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-18-7/FlexibleArrayMembersDeclared.ql b/c/misra/src/rules/RULE-18-7/FlexibleArrayMembersDeclared.ql index 5ae2c9b9c6..73f0732ba5 100644 --- a/c/misra/src/rules/RULE-18-7/FlexibleArrayMembersDeclared.ql +++ b/c/misra/src/rules/RULE-18-7/FlexibleArrayMembersDeclared.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-18-7 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-18-8/VariableLengthArrayTypesUsed.ql b/c/misra/src/rules/RULE-18-8/VariableLengthArrayTypesUsed.ql index 00d02cdc02..a7c25ed35e 100644 --- a/c/misra/src/rules/RULE-18-8/VariableLengthArrayTypesUsed.ql +++ b/c/misra/src/rules/RULE-18-8/VariableLengthArrayTypesUsed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-18-8 * correctness * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-19-1/ObjectAssignedToAnOverlappingObject.ql b/c/misra/src/rules/RULE-19-1/ObjectAssignedToAnOverlappingObject.ql index b39ce4fba4..31c24dcdd8 100644 --- a/c/misra/src/rules/RULE-19-1/ObjectAssignedToAnOverlappingObject.ql +++ b/c/misra/src/rules/RULE-19-1/ObjectAssignedToAnOverlappingObject.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-19-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-19-1/ObjectCopiedToAnOverlappingObject.ql b/c/misra/src/rules/RULE-19-1/ObjectCopiedToAnOverlappingObject.ql index bee9b41e2c..e3e85faf34 100644 --- a/c/misra/src/rules/RULE-19-1/ObjectCopiedToAnOverlappingObject.ql +++ b/c/misra/src/rules/RULE-19-1/ObjectCopiedToAnOverlappingObject.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-19-1 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-19-2/UnionKeywordShouldNotBeUsed.ql b/c/misra/src/rules/RULE-19-2/UnionKeywordShouldNotBeUsed.ql index b3028d9add..14d01c47e3 100644 --- a/c/misra/src/rules/RULE-19-2/UnionKeywordShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-19-2/UnionKeywordShouldNotBeUsed.ql @@ -7,6 +7,7 @@ * @problem.severity warning * @tags external/misra/id/rule-19-2 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-2-1/UnreachableCode.ql b/c/misra/src/rules/RULE-2-1/UnreachableCode.ql index 5de46fd9ea..020338913a 100644 --- a/c/misra/src/rules/RULE-2-1/UnreachableCode.ql +++ b/c/misra/src/rules/RULE-2-1/UnreachableCode.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-2-1 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-2-2/DeadCode.ql b/c/misra/src/rules/RULE-2-2/DeadCode.ql index c9ecb5e934..19ac69c2c1 100644 --- a/c/misra/src/rules/RULE-2-2/DeadCode.ql +++ b/c/misra/src/rules/RULE-2-2/DeadCode.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-2-2 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-2-3/UnusedTypeDeclarations.ql b/c/misra/src/rules/RULE-2-3/UnusedTypeDeclarations.ql index 3192ee960f..b4c6bbf42c 100644 --- a/c/misra/src/rules/RULE-2-3/UnusedTypeDeclarations.ql +++ b/c/misra/src/rules/RULE-2-3/UnusedTypeDeclarations.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-2-3 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-2-4/UnusedTagDeclaration.ql b/c/misra/src/rules/RULE-2-4/UnusedTagDeclaration.ql index c10985f28c..08fe2568e9 100644 --- a/c/misra/src/rules/RULE-2-4/UnusedTagDeclaration.ql +++ b/c/misra/src/rules/RULE-2-4/UnusedTagDeclaration.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-2-4 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-2-5/UnusedMacroDeclaration.ql b/c/misra/src/rules/RULE-2-5/UnusedMacroDeclaration.ql index ed2b1f6065..b7ea9f64de 100644 --- a/c/misra/src/rules/RULE-2-5/UnusedMacroDeclaration.ql +++ b/c/misra/src/rules/RULE-2-5/UnusedMacroDeclaration.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-2-5 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-2-6/UnusedLabelDeclaration.ql b/c/misra/src/rules/RULE-2-6/UnusedLabelDeclaration.ql index 4ab96707e4..7838c5fc1f 100644 --- a/c/misra/src/rules/RULE-2-6/UnusedLabelDeclaration.ql +++ b/c/misra/src/rules/RULE-2-6/UnusedLabelDeclaration.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-2-6 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-2-7/UnusedParameter.ql b/c/misra/src/rules/RULE-2-7/UnusedParameter.ql index b9c2f32f60..e27caee50b 100644 --- a/c/misra/src/rules/RULE-2-7/UnusedParameter.ql +++ b/c/misra/src/rules/RULE-2-7/UnusedParameter.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-2-7 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-20-1/IncludeDirectivesPrecededByDirectivesOrComments.ql b/c/misra/src/rules/RULE-20-1/IncludeDirectivesPrecededByDirectivesOrComments.ql index aa0d733eb2..ba78abcb5e 100644 --- a/c/misra/src/rules/RULE-20-1/IncludeDirectivesPrecededByDirectivesOrComments.ql +++ b/c/misra/src/rules/RULE-20-1/IncludeDirectivesPrecededByDirectivesOrComments.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-20-1 * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-20-10/PreprocessorHashOperatorsShouldNotBeUsed.ql b/c/misra/src/rules/RULE-20-10/PreprocessorHashOperatorsShouldNotBeUsed.ql index f0d82928fb..016589af94 100644 --- a/c/misra/src/rules/RULE-20-10/PreprocessorHashOperatorsShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-20-10/PreprocessorHashOperatorsShouldNotBeUsed.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-20-10 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql b/c/misra/src/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql index 42ea398e14..fc87186d3e 100644 --- a/c/misra/src/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql +++ b/c/misra/src/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-20-11 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql b/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql index 8b9d6ca763..da66f66fb2 100644 --- a/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql +++ b/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-20-12 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-20-2/ForbiddenCharactersInHeaderFileName.ql b/c/misra/src/rules/RULE-20-2/ForbiddenCharactersInHeaderFileName.ql index a9b27e8669..d9942c3e56 100644 --- a/c/misra/src/rules/RULE-20-2/ForbiddenCharactersInHeaderFileName.ql +++ b/c/misra/src/rules/RULE-20-2/ForbiddenCharactersInHeaderFileName.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-20-2 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-20-4/MacroDefinedWithTheSameNameAsKeyword.ql b/c/misra/src/rules/RULE-20-4/MacroDefinedWithTheSameNameAsKeyword.ql index 6b9ae71120..210e081bb1 100644 --- a/c/misra/src/rules/RULE-20-4/MacroDefinedWithTheSameNameAsKeyword.ql +++ b/c/misra/src/rules/RULE-20-4/MacroDefinedWithTheSameNameAsKeyword.ql @@ -11,6 +11,7 @@ * correctness * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-20-5/UndefShouldNotBeUsed.ql b/c/misra/src/rules/RULE-20-5/UndefShouldNotBeUsed.ql index c253c795e8..15bec51bf8 100644 --- a/c/misra/src/rules/RULE-20-5/UndefShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-20-5/UndefShouldNotBeUsed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-20-5 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-20-6/FunctionLikeMacroArgsContainHashTokenCQuery.ql b/c/misra/src/rules/RULE-20-6/FunctionLikeMacroArgsContainHashTokenCQuery.ql index 3e212dc972..e0fc8e4510 100644 --- a/c/misra/src/rules/RULE-20-6/FunctionLikeMacroArgsContainHashTokenCQuery.ql +++ b/c/misra/src/rules/RULE-20-6/FunctionLikeMacroArgsContainHashTokenCQuery.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-20-6 * readability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-20-7/MacroParameterNotEnclosedInParenthesesCQuery.ql b/c/misra/src/rules/RULE-20-7/MacroParameterNotEnclosedInParenthesesCQuery.ql index ad4882d07c..e557f99a18 100644 --- a/c/misra/src/rules/RULE-20-7/MacroParameterNotEnclosedInParenthesesCQuery.ql +++ b/c/misra/src/rules/RULE-20-7/MacroParameterNotEnclosedInParenthesesCQuery.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-20-7 * correctness * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-20-8/ControllingExpressionIfDirective.ql b/c/misra/src/rules/RULE-20-8/ControllingExpressionIfDirective.ql index cd55e03ee0..5e2c1fbc27 100644 --- a/c/misra/src/rules/RULE-20-8/ControllingExpressionIfDirective.ql +++ b/c/misra/src/rules/RULE-20-8/ControllingExpressionIfDirective.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-20-8 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-20-9/IdentifiersUsedInPreprocessorExpression.ql b/c/misra/src/rules/RULE-20-9/IdentifiersUsedInPreprocessorExpression.ql index 15ca323038..be6f3c00f3 100644 --- a/c/misra/src/rules/RULE-20-9/IdentifiersUsedInPreprocessorExpression.ql +++ b/c/misra/src/rules/RULE-20-9/IdentifiersUsedInPreprocessorExpression.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-20-9 * correctness * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-1/DefineAndUndefUsedOnReservedIdentifierOrMacroName.ql b/c/misra/src/rules/RULE-21-1/DefineAndUndefUsedOnReservedIdentifierOrMacroName.ql index b37b5cb92e..86d8426df8 100644 --- a/c/misra/src/rules/RULE-21-1/DefineAndUndefUsedOnReservedIdentifierOrMacroName.ql +++ b/c/misra/src/rules/RULE-21-1/DefineAndUndefUsedOnReservedIdentifierOrMacroName.ql @@ -10,6 +10,7 @@ * correctness * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-10/StandardLibraryTimeAndDateFunctionsUsed.ql b/c/misra/src/rules/RULE-21-10/StandardLibraryTimeAndDateFunctionsUsed.ql index c519ebe701..0ad9c350f2 100644 --- a/c/misra/src/rules/RULE-21-10/StandardLibraryTimeAndDateFunctionsUsed.ql +++ b/c/misra/src/rules/RULE-21-10/StandardLibraryTimeAndDateFunctionsUsed.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-21-10 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-11/StandardHeaderFileTgmathhUsed.ql b/c/misra/src/rules/RULE-21-11/StandardHeaderFileTgmathhUsed.ql index 5a33f94fb6..1c6b1bcd3d 100644 --- a/c/misra/src/rules/RULE-21-11/StandardHeaderFileTgmathhUsed.ql +++ b/c/misra/src/rules/RULE-21-11/StandardHeaderFileTgmathhUsed.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-21-11 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-12/ExceptionHandlingFeaturesOfFenvhUsed.ql b/c/misra/src/rules/RULE-21-12/ExceptionHandlingFeaturesOfFenvhUsed.ql index 727cb190e9..33da2f5d03 100644 --- a/c/misra/src/rules/RULE-21-12/ExceptionHandlingFeaturesOfFenvhUsed.ql +++ b/c/misra/src/rules/RULE-21-12/ExceptionHandlingFeaturesOfFenvhUsed.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-21-12 * correctness + * external/misra/c/2012/amendment2 * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-21-13/CtypeFunctionArgNotUnsignedCharOrEof.ql b/c/misra/src/rules/RULE-21-13/CtypeFunctionArgNotUnsignedCharOrEof.ql index 70ec91e3c1..b7ccf534fa 100644 --- a/c/misra/src/rules/RULE-21-13/CtypeFunctionArgNotUnsignedCharOrEof.ql +++ b/c/misra/src/rules/RULE-21-13/CtypeFunctionArgNotUnsignedCharOrEof.ql @@ -7,6 +7,7 @@ * @precision very-high * @problem.severity error * @tags external/misra/id/rule-21-13 + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-21-14/MemcmpUsedToCompareNullTerminatedStrings.ql b/c/misra/src/rules/RULE-21-14/MemcmpUsedToCompareNullTerminatedStrings.ql index 44e21d14db..c51ff10744 100644 --- a/c/misra/src/rules/RULE-21-14/MemcmpUsedToCompareNullTerminatedStrings.ql +++ b/c/misra/src/rules/RULE-21-14/MemcmpUsedToCompareNullTerminatedStrings.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-21-14 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-15/MemcpyMemmoveMemcmpArgNotPointersToCompatibleTypes.ql b/c/misra/src/rules/RULE-21-15/MemcpyMemmoveMemcmpArgNotPointersToCompatibleTypes.ql index 956fc5383e..f5d8057b3a 100644 --- a/c/misra/src/rules/RULE-21-15/MemcpyMemmoveMemcmpArgNotPointersToCompatibleTypes.ql +++ b/c/misra/src/rules/RULE-21-15/MemcpyMemmoveMemcmpArgNotPointersToCompatibleTypes.ql @@ -7,6 +7,7 @@ * @precision very-high * @problem.severity error * @tags external/misra/id/rule-21-15 + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-16/MemcmpOnInappropriateEssentialTypeArgs.ql b/c/misra/src/rules/RULE-21-16/MemcmpOnInappropriateEssentialTypeArgs.ql index 1a939e920c..cb70567660 100644 --- a/c/misra/src/rules/RULE-21-16/MemcmpOnInappropriateEssentialTypeArgs.ql +++ b/c/misra/src/rules/RULE-21-16/MemcmpOnInappropriateEssentialTypeArgs.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-21-16 * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-17/StringFunctionPointerArgumentOutOfBounds.ql b/c/misra/src/rules/RULE-21-17/StringFunctionPointerArgumentOutOfBounds.ql index a4850781f6..31d3434c58 100644 --- a/c/misra/src/rules/RULE-21-17/StringFunctionPointerArgumentOutOfBounds.ql +++ b/c/misra/src/rules/RULE-21-17/StringFunctionPointerArgumentOutOfBounds.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-21-17 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-21-18/StringLibrarySizeArgumentOutOfBounds.ql b/c/misra/src/rules/RULE-21-18/StringLibrarySizeArgumentOutOfBounds.ql index 3554b2791e..22ccc14b69 100644 --- a/c/misra/src/rules/RULE-21-18/StringLibrarySizeArgumentOutOfBounds.ql +++ b/c/misra/src/rules/RULE-21-18/StringLibrarySizeArgumentOutOfBounds.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-21-18 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-21-19/ValuesReturnedByLocaleSettingUsedAsPtrToConst.ql b/c/misra/src/rules/RULE-21-19/ValuesReturnedByLocaleSettingUsedAsPtrToConst.ql index 0e02cc1d84..6fa3ad92be 100644 --- a/c/misra/src/rules/RULE-21-19/ValuesReturnedByLocaleSettingUsedAsPtrToConst.ql +++ b/c/misra/src/rules/RULE-21-19/ValuesReturnedByLocaleSettingUsedAsPtrToConst.ql @@ -9,6 +9,7 @@ * @problem.severity error * @tags external/misra/id/rule-21-19 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-21-2/DoNotDeclareAReservedIdentifier.ql b/c/misra/src/rules/RULE-21-2/DoNotDeclareAReservedIdentifier.ql index 89140222da..80ad8386bc 100644 --- a/c/misra/src/rules/RULE-21-2/DoNotDeclareAReservedIdentifier.ql +++ b/c/misra/src/rules/RULE-21-2/DoNotDeclareAReservedIdentifier.ql @@ -9,6 +9,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-20/CallToSetlocaleInvalidatesOldPointers.ql b/c/misra/src/rules/RULE-21-20/CallToSetlocaleInvalidatesOldPointers.ql index c193e899db..6441add7fc 100644 --- a/c/misra/src/rules/RULE-21-20/CallToSetlocaleInvalidatesOldPointers.ql +++ b/c/misra/src/rules/RULE-21-20/CallToSetlocaleInvalidatesOldPointers.ql @@ -9,6 +9,7 @@ * @problem.severity error * @tags external/misra/id/rule-21-20 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-21-20/CallToSetlocaleInvalidatesOldPointersWarn.ql b/c/misra/src/rules/RULE-21-20/CallToSetlocaleInvalidatesOldPointersWarn.ql index 0bbcb045d9..e7e97e2639 100644 --- a/c/misra/src/rules/RULE-21-20/CallToSetlocaleInvalidatesOldPointersWarn.ql +++ b/c/misra/src/rules/RULE-21-20/CallToSetlocaleInvalidatesOldPointersWarn.ql @@ -9,6 +9,7 @@ * @problem.severity warning * @tags external/misra/id/rule-21-20 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-21-21/SystemOfStdlibhUsed.ql b/c/misra/src/rules/RULE-21-21/SystemOfStdlibhUsed.ql index b38f159c14..81dd6ba1a3 100644 --- a/c/misra/src/rules/RULE-21-21/SystemOfStdlibhUsed.ql +++ b/c/misra/src/rules/RULE-21-21/SystemOfStdlibhUsed.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-21-21 * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-3/MemoryAllocDeallocFunctionsOfStdlibhUsed.ql b/c/misra/src/rules/RULE-21-3/MemoryAllocDeallocFunctionsOfStdlibhUsed.ql index ed3317b696..ab3ba3e328 100644 --- a/c/misra/src/rules/RULE-21-3/MemoryAllocDeallocFunctionsOfStdlibhUsed.ql +++ b/c/misra/src/rules/RULE-21-3/MemoryAllocDeallocFunctionsOfStdlibhUsed.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-21-3 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-4/StandardHeaderFileUsedSetjmph.ql b/c/misra/src/rules/RULE-21-4/StandardHeaderFileUsedSetjmph.ql index 6de73499c0..88ad0aa6db 100644 --- a/c/misra/src/rules/RULE-21-4/StandardHeaderFileUsedSetjmph.ql +++ b/c/misra/src/rules/RULE-21-4/StandardHeaderFileUsedSetjmph.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-21-4 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-5/StandardHeaderFileUsedSignalh.ql b/c/misra/src/rules/RULE-21-5/StandardHeaderFileUsedSignalh.ql index 004060b5a5..d22ee55742 100644 --- a/c/misra/src/rules/RULE-21-5/StandardHeaderFileUsedSignalh.ql +++ b/c/misra/src/rules/RULE-21-5/StandardHeaderFileUsedSignalh.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-21-5 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-6/StandardLibraryInputoutputFunctionsUsed.ql b/c/misra/src/rules/RULE-21-6/StandardLibraryInputoutputFunctionsUsed.ql index 6ef8c84cfe..6395ddc5ac 100644 --- a/c/misra/src/rules/RULE-21-6/StandardLibraryInputoutputFunctionsUsed.ql +++ b/c/misra/src/rules/RULE-21-6/StandardLibraryInputoutputFunctionsUsed.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-21-6 * security * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql b/c/misra/src/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql index 7263e91d53..ce781403b1 100644 --- a/c/misra/src/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql +++ b/c/misra/src/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-21-7 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-8/TerminationFunctionsOfStdlibhUsed.ql b/c/misra/src/rules/RULE-21-8/TerminationFunctionsOfStdlibhUsed.ql index 3414e82ab2..cbc7dd5a92 100644 --- a/c/misra/src/rules/RULE-21-8/TerminationFunctionsOfStdlibhUsed.ql +++ b/c/misra/src/rules/RULE-21-8/TerminationFunctionsOfStdlibhUsed.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-21-8 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-8/TerminationMacrosOfStdlibhUsed.ql b/c/misra/src/rules/RULE-21-8/TerminationMacrosOfStdlibhUsed.ql index 2f83ec6b70..7a911c1525 100644 --- a/c/misra/src/rules/RULE-21-8/TerminationMacrosOfStdlibhUsed.ql +++ b/c/misra/src/rules/RULE-21-8/TerminationMacrosOfStdlibhUsed.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-21-8 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-21-9/BsearchAndQsortOfStdlibhUsed.ql b/c/misra/src/rules/RULE-21-9/BsearchAndQsortOfStdlibhUsed.ql index b446b7f3f6..6759fa93d1 100644 --- a/c/misra/src/rules/RULE-21-9/BsearchAndQsortOfStdlibhUsed.ql +++ b/c/misra/src/rules/RULE-21-9/BsearchAndQsortOfStdlibhUsed.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-21-9 * security * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-22-1/CloseFileHandleWhenNoLongerNeededMisra.ql b/c/misra/src/rules/RULE-22-1/CloseFileHandleWhenNoLongerNeededMisra.ql index c756bc2526..d888d87b6c 100644 --- a/c/misra/src/rules/RULE-22-1/CloseFileHandleWhenNoLongerNeededMisra.ql +++ b/c/misra/src/rules/RULE-22-1/CloseFileHandleWhenNoLongerNeededMisra.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-22-1 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-22-1/FreeMemoryWhenNoLongerNeededMisra.ql b/c/misra/src/rules/RULE-22-1/FreeMemoryWhenNoLongerNeededMisra.ql index 1650590559..ca5853dac9 100644 --- a/c/misra/src/rules/RULE-22-1/FreeMemoryWhenNoLongerNeededMisra.ql +++ b/c/misra/src/rules/RULE-22-1/FreeMemoryWhenNoLongerNeededMisra.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-22-1 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-22-10/OnlyTestErrnoRightAfterErrnoSettingFunction.ql b/c/misra/src/rules/RULE-22-10/OnlyTestErrnoRightAfterErrnoSettingFunction.ql index eab5a0c089..50e5350936 100644 --- a/c/misra/src/rules/RULE-22-10/OnlyTestErrnoRightAfterErrnoSettingFunction.ql +++ b/c/misra/src/rules/RULE-22-10/OnlyTestErrnoRightAfterErrnoSettingFunction.ql @@ -9,6 +9,7 @@ * @problem.severity warning * @tags external/misra/id/rule-22-10 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-22-2/OnlyFreeMemoryAllocatedDynamicallyMisra.ql b/c/misra/src/rules/RULE-22-2/OnlyFreeMemoryAllocatedDynamicallyMisra.ql index a149103c9a..cdbe8e2c16 100644 --- a/c/misra/src/rules/RULE-22-2/OnlyFreeMemoryAllocatedDynamicallyMisra.ql +++ b/c/misra/src/rules/RULE-22-2/OnlyFreeMemoryAllocatedDynamicallyMisra.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-22-2 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-22-3/FileOpenForReadAndWriteOnDifferentStreams.ql b/c/misra/src/rules/RULE-22-3/FileOpenForReadAndWriteOnDifferentStreams.ql index c01afea39f..ee103ca6dc 100644 --- a/c/misra/src/rules/RULE-22-3/FileOpenForReadAndWriteOnDifferentStreams.ql +++ b/c/misra/src/rules/RULE-22-3/FileOpenForReadAndWriteOnDifferentStreams.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-22-3 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-22-4/AttemptToWriteToAReadOnlyStream.ql b/c/misra/src/rules/RULE-22-4/AttemptToWriteToAReadOnlyStream.ql index 6dc3b3ee71..19bad99baa 100644 --- a/c/misra/src/rules/RULE-22-4/AttemptToWriteToAReadOnlyStream.ql +++ b/c/misra/src/rules/RULE-22-4/AttemptToWriteToAReadOnlyStream.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-22-4 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-22-5/PointerToAFileObjectDereferenced.ql b/c/misra/src/rules/RULE-22-5/PointerToAFileObjectDereferenced.ql index 86e0b76e21..05cc4e3433 100644 --- a/c/misra/src/rules/RULE-22-5/PointerToAFileObjectDereferenced.ql +++ b/c/misra/src/rules/RULE-22-5/PointerToAFileObjectDereferenced.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-22-5 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-22-6/FileUsedAfterClosed.ql b/c/misra/src/rules/RULE-22-6/FileUsedAfterClosed.ql index 78c5063ddd..64318dbedd 100644 --- a/c/misra/src/rules/RULE-22-6/FileUsedAfterClosed.ql +++ b/c/misra/src/rules/RULE-22-6/FileUsedAfterClosed.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-22-6 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-22-7/EofShallBeComparedWithUnmodifiedReturnValues.ql b/c/misra/src/rules/RULE-22-7/EofShallBeComparedWithUnmodifiedReturnValues.ql index 307357a93a..a29ee7c898 100644 --- a/c/misra/src/rules/RULE-22-7/EofShallBeComparedWithUnmodifiedReturnValues.ql +++ b/c/misra/src/rules/RULE-22-7/EofShallBeComparedWithUnmodifiedReturnValues.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-22-7 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-22-8/ErrnoSetToZeroPriorToCall.ql b/c/misra/src/rules/RULE-22-8/ErrnoSetToZeroPriorToCall.ql index de9a083545..6a39070ef0 100644 --- a/c/misra/src/rules/RULE-22-8/ErrnoSetToZeroPriorToCall.ql +++ b/c/misra/src/rules/RULE-22-8/ErrnoSetToZeroPriorToCall.ql @@ -9,6 +9,7 @@ * @problem.severity error * @tags external/misra/id/rule-22-8 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-22-9/ErrnoSetToZeroAfterCall.ql b/c/misra/src/rules/RULE-22-9/ErrnoSetToZeroAfterCall.ql index da4504b75b..274bf5b2ae 100644 --- a/c/misra/src/rules/RULE-22-9/ErrnoSetToZeroAfterCall.ql +++ b/c/misra/src/rules/RULE-22-9/ErrnoSetToZeroAfterCall.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-22-9 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-3-1/CharacterSequencesAndUsedWithinAComment.ql b/c/misra/src/rules/RULE-3-1/CharacterSequencesAndUsedWithinAComment.ql index f59606a0ac..6eb605dbd9 100644 --- a/c/misra/src/rules/RULE-3-1/CharacterSequencesAndUsedWithinAComment.ql +++ b/c/misra/src/rules/RULE-3-1/CharacterSequencesAndUsedWithinAComment.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-3-1 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-3-2/LineSplicingUsedInComments.ql b/c/misra/src/rules/RULE-3-2/LineSplicingUsedInComments.ql index cf6a2bb547..f1fd85b129 100644 --- a/c/misra/src/rules/RULE-3-2/LineSplicingUsedInComments.ql +++ b/c/misra/src/rules/RULE-3-2/LineSplicingUsedInComments.ql @@ -10,6 +10,7 @@ * maintainability * readability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql b/c/misra/src/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql index fd77f1a688..0f04a7362b 100644 --- a/c/misra/src/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql +++ b/c/misra/src/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql @@ -10,6 +10,7 @@ * maintainability * readability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-1/ExternalIdentifiersNotDistinct.ql b/c/misra/src/rules/RULE-5-1/ExternalIdentifiersNotDistinct.ql index fa7190c39b..2c2c302bc0 100644 --- a/c/misra/src/rules/RULE-5-1/ExternalIdentifiersNotDistinct.ql +++ b/c/misra/src/rules/RULE-5-1/ExternalIdentifiersNotDistinct.ql @@ -9,6 +9,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-2/IdentifiersDeclaredInTheSameScopeNotDistinct.ql b/c/misra/src/rules/RULE-5-2/IdentifiersDeclaredInTheSameScopeNotDistinct.ql index 682d7538c5..eb24d1c094 100644 --- a/c/misra/src/rules/RULE-5-2/IdentifiersDeclaredInTheSameScopeNotDistinct.ql +++ b/c/misra/src/rules/RULE-5-2/IdentifiersDeclaredInTheSameScopeNotDistinct.ql @@ -9,6 +9,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-3/IdentifierHidingC.ql b/c/misra/src/rules/RULE-5-3/IdentifierHidingC.ql index 3463d08e1c..1c54b70147 100644 --- a/c/misra/src/rules/RULE-5-3/IdentifierHidingC.ql +++ b/c/misra/src/rules/RULE-5-3/IdentifierHidingC.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-5-3 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-4/MacroIdentifierNotDistinctFromParameter.ql b/c/misra/src/rules/RULE-5-4/MacroIdentifierNotDistinctFromParameter.ql index 886e05f0ea..d8a78cb680 100644 --- a/c/misra/src/rules/RULE-5-4/MacroIdentifierNotDistinctFromParameter.ql +++ b/c/misra/src/rules/RULE-5-4/MacroIdentifierNotDistinctFromParameter.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-5-4 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-4/MacroIdentifiersNotDistinct.ql b/c/misra/src/rules/RULE-5-4/MacroIdentifiersNotDistinct.ql index 5b3683bdc4..abd22068dd 100644 --- a/c/misra/src/rules/RULE-5-4/MacroIdentifiersNotDistinct.ql +++ b/c/misra/src/rules/RULE-5-4/MacroIdentifiersNotDistinct.ql @@ -9,6 +9,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql b/c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql index a63d9656b8..da6b725ab5 100644 --- a/c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql +++ b/c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-5-5 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-6/TypedefNameNotUnique.ql b/c/misra/src/rules/RULE-5-6/TypedefNameNotUnique.ql index 2e9126d3af..1398df6a4d 100644 --- a/c/misra/src/rules/RULE-5-6/TypedefNameNotUnique.ql +++ b/c/misra/src/rules/RULE-5-6/TypedefNameNotUnique.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-5-6 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-7/TagNameNotUnique.ql b/c/misra/src/rules/RULE-5-7/TagNameNotUnique.ql index 1c8a7a6b34..fa6560ab49 100644 --- a/c/misra/src/rules/RULE-5-7/TagNameNotUnique.ql +++ b/c/misra/src/rules/RULE-5-7/TagNameNotUnique.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-5-7 * readability * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-8/IdentifiersWithExternalLinkageNotUnique.ql b/c/misra/src/rules/RULE-5-8/IdentifiersWithExternalLinkageNotUnique.ql index 1b21dd273e..fa1b2b1fad 100644 --- a/c/misra/src/rules/RULE-5-8/IdentifiersWithExternalLinkageNotUnique.ql +++ b/c/misra/src/rules/RULE-5-8/IdentifiersWithExternalLinkageNotUnique.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-5-8 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-5-9/IdentifiersWithInternalLinkageNotUnique.ql b/c/misra/src/rules/RULE-5-9/IdentifiersWithInternalLinkageNotUnique.ql index 45f63a3207..fcba48f2fd 100644 --- a/c/misra/src/rules/RULE-5-9/IdentifiersWithInternalLinkageNotUnique.ql +++ b/c/misra/src/rules/RULE-5-9/IdentifiersWithInternalLinkageNotUnique.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-5-9 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql b/c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql index f5bc589a4d..078c2c48b7 100644 --- a/c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql +++ b/c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql @@ -7,6 +7,7 @@ * @precision very-high * @problem.severity error * @tags external/misra/id/rule-6-1 + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql b/c/misra/src/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql index d699c1c9b7..142a0b542d 100644 --- a/c/misra/src/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql +++ b/c/misra/src/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql @@ -7,6 +7,7 @@ * @precision very-high * @problem.severity error * @tags external/misra/id/rule-6-2 + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-6-3/BitFieldDeclaredAsMemberOfAUnion.ql b/c/misra/src/rules/RULE-6-3/BitFieldDeclaredAsMemberOfAUnion.ql index 5fcf938046..4befbb9dd6 100644 --- a/c/misra/src/rules/RULE-6-3/BitFieldDeclaredAsMemberOfAUnion.ql +++ b/c/misra/src/rules/RULE-6-3/BitFieldDeclaredAsMemberOfAUnion.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-6-3 * correctness + * external/misra/c/2012/amendment3 * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-7-1/OctalConstantsUsed.ql b/c/misra/src/rules/RULE-7-1/OctalConstantsUsed.ql index d4a6c332a7..9934e80487 100644 --- a/c/misra/src/rules/RULE-7-1/OctalConstantsUsed.ql +++ b/c/misra/src/rules/RULE-7-1/OctalConstantsUsed.ql @@ -10,6 +10,7 @@ * readability * correctness * maintainability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-7-2/UOrUSuffixRepresentedInUnsignedType.ql b/c/misra/src/rules/RULE-7-2/UOrUSuffixRepresentedInUnsignedType.ql index b8f8d59718..c02e0e2aca 100644 --- a/c/misra/src/rules/RULE-7-2/UOrUSuffixRepresentedInUnsignedType.ql +++ b/c/misra/src/rules/RULE-7-2/UOrUSuffixRepresentedInUnsignedType.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-7-2 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql b/c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql index 85c14ff419..0b38b26eea 100644 --- a/c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql +++ b/c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-7-3 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.ql b/c/misra/src/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.ql index c93740139b..bc2fa5f5bf 100644 --- a/c/misra/src/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.ql +++ b/c/misra/src/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.ql @@ -7,6 +7,7 @@ * @precision very-high * @problem.severity error * @tags external/misra/id/rule-7-4 + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-1/ExplicitlyDeclareTypes.ql b/c/misra/src/rules/RULE-8-1/ExplicitlyDeclareTypes.ql index bfcbac4435..6484372f5b 100644 --- a/c/misra/src/rules/RULE-8-1/ExplicitlyDeclareTypes.ql +++ b/c/misra/src/rules/RULE-8-1/ExplicitlyDeclareTypes.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-8-1 * correctness * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-10/InlineFunctionNotDeclaredStaticStorage.ql b/c/misra/src/rules/RULE-8-10/InlineFunctionNotDeclaredStaticStorage.ql index 47e80912af..250c00ca2e 100644 --- a/c/misra/src/rules/RULE-8-10/InlineFunctionNotDeclaredStaticStorage.ql +++ b/c/misra/src/rules/RULE-8-10/InlineFunctionNotDeclaredStaticStorage.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-8-10 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-11/ArrayExternalLinkageSizeExplicitlySpecified.ql b/c/misra/src/rules/RULE-8-11/ArrayExternalLinkageSizeExplicitlySpecified.ql index ada18c805d..d14e236755 100644 --- a/c/misra/src/rules/RULE-8-11/ArrayExternalLinkageSizeExplicitlySpecified.ql +++ b/c/misra/src/rules/RULE-8-11/ArrayExternalLinkageSizeExplicitlySpecified.ql @@ -10,6 +10,7 @@ * @tags external/misra/id/rule-8-11 * correctness * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql b/c/misra/src/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql index a4fcb0e4f3..6ebabc3810 100644 --- a/c/misra/src/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql +++ b/c/misra/src/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-8-12 * correctness * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-13/PointerShouldPointToConstTypeWhenPossible.ql b/c/misra/src/rules/RULE-8-13/PointerShouldPointToConstTypeWhenPossible.ql index 48bd9967b2..8b405d138c 100644 --- a/c/misra/src/rules/RULE-8-13/PointerShouldPointToConstTypeWhenPossible.ql +++ b/c/misra/src/rules/RULE-8-13/PointerShouldPointToConstTypeWhenPossible.ql @@ -10,6 +10,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-8-14/RestrictTypeQualifierUsed.ql b/c/misra/src/rules/RULE-8-14/RestrictTypeQualifierUsed.ql index 1969947753..cff7d0df5c 100644 --- a/c/misra/src/rules/RULE-8-14/RestrictTypeQualifierUsed.ql +++ b/c/misra/src/rules/RULE-8-14/RestrictTypeQualifierUsed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-8-14 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql b/c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql index e46085750d..73294d776b 100644 --- a/c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql +++ b/c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-8-2 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-3/DeclarationsOfAFunctionSameNameAndType.ql b/c/misra/src/rules/RULE-8-3/DeclarationsOfAFunctionSameNameAndType.ql index 6803af9380..8c80c64a40 100644 --- a/c/misra/src/rules/RULE-8-3/DeclarationsOfAFunctionSameNameAndType.ql +++ b/c/misra/src/rules/RULE-8-3/DeclarationsOfAFunctionSameNameAndType.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-8-3 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-3/DeclarationsOfAnObjectSameNameAndType.ql b/c/misra/src/rules/RULE-8-3/DeclarationsOfAnObjectSameNameAndType.ql index d68382503a..421998c582 100644 --- a/c/misra/src/rules/RULE-8-3/DeclarationsOfAnObjectSameNameAndType.ql +++ b/c/misra/src/rules/RULE-8-3/DeclarationsOfAnObjectSameNameAndType.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-8-3 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-4/CompatibleDeclarationFunctionDefined.ql b/c/misra/src/rules/RULE-8-4/CompatibleDeclarationFunctionDefined.ql index c87e5b556c..63f70d3541 100644 --- a/c/misra/src/rules/RULE-8-4/CompatibleDeclarationFunctionDefined.ql +++ b/c/misra/src/rules/RULE-8-4/CompatibleDeclarationFunctionDefined.ql @@ -10,6 +10,7 @@ * readability * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-4/CompatibleDeclarationObjectDefined.ql b/c/misra/src/rules/RULE-8-4/CompatibleDeclarationObjectDefined.ql index 433597cf4a..7e5baacd9a 100644 --- a/c/misra/src/rules/RULE-8-4/CompatibleDeclarationObjectDefined.ql +++ b/c/misra/src/rules/RULE-8-4/CompatibleDeclarationObjectDefined.ql @@ -10,6 +10,7 @@ * readability * maintainability * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-5/ExternalObjectOrFunctionNotDeclaredInOneFile.ql b/c/misra/src/rules/RULE-8-5/ExternalObjectOrFunctionNotDeclaredInOneFile.ql index 56e1d742a6..9a3f1c7900 100644 --- a/c/misra/src/rules/RULE-8-5/ExternalObjectOrFunctionNotDeclaredInOneFile.ql +++ b/c/misra/src/rules/RULE-8-5/ExternalObjectOrFunctionNotDeclaredInOneFile.ql @@ -7,6 +7,7 @@ * @problem.severity warning * @tags external/misra/id/rule-8-5 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-6/IdentifierWithExternalLinkageOneDefinition.ql b/c/misra/src/rules/RULE-8-6/IdentifierWithExternalLinkageOneDefinition.ql index 1a85775236..0781eef539 100644 --- a/c/misra/src/rules/RULE-8-6/IdentifierWithExternalLinkageOneDefinition.ql +++ b/c/misra/src/rules/RULE-8-6/IdentifierWithExternalLinkageOneDefinition.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-8-6 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-7/ShouldNotBeDefinedWithExternalLinkage.ql b/c/misra/src/rules/RULE-8-7/ShouldNotBeDefinedWithExternalLinkage.ql index 824a4cf1cf..faa915fdd5 100644 --- a/c/misra/src/rules/RULE-8-7/ShouldNotBeDefinedWithExternalLinkage.ql +++ b/c/misra/src/rules/RULE-8-7/ShouldNotBeDefinedWithExternalLinkage.ql @@ -12,6 +12,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-8-8/MissingStaticSpecifierFunctionRedeclarationC.ql b/c/misra/src/rules/RULE-8-8/MissingStaticSpecifierFunctionRedeclarationC.ql index c210273cd1..c3a5ce897f 100644 --- a/c/misra/src/rules/RULE-8-8/MissingStaticSpecifierFunctionRedeclarationC.ql +++ b/c/misra/src/rules/RULE-8-8/MissingStaticSpecifierFunctionRedeclarationC.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-8-8 * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-8/MissingStaticSpecifierObjectRedeclarationC.ql b/c/misra/src/rules/RULE-8-8/MissingStaticSpecifierObjectRedeclarationC.ql index 2cb65c4fda..65c878e883 100644 --- a/c/misra/src/rules/RULE-8-8/MissingStaticSpecifierObjectRedeclarationC.ql +++ b/c/misra/src/rules/RULE-8-8/MissingStaticSpecifierObjectRedeclarationC.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-8-8 * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-8-9/UnnecessaryExposedIdentifierDeclarationC.ql b/c/misra/src/rules/RULE-8-9/UnnecessaryExposedIdentifierDeclarationC.ql index 88cf72fdcd..5dc697e425 100644 --- a/c/misra/src/rules/RULE-8-9/UnnecessaryExposedIdentifierDeclarationC.ql +++ b/c/misra/src/rules/RULE-8-9/UnnecessaryExposedIdentifierDeclarationC.ql @@ -8,6 +8,7 @@ * @problem.severity warning * @tags external/misra/id/rule-8-9 * correctness + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-9-1/ObjectWithAutoStorageDurationReadBeforeInit.ql b/c/misra/src/rules/RULE-9-1/ObjectWithAutoStorageDurationReadBeforeInit.ql index b9960fc886..f3204ef2e3 100644 --- a/c/misra/src/rules/RULE-9-1/ObjectWithAutoStorageDurationReadBeforeInit.ql +++ b/c/misra/src/rules/RULE-9-1/ObjectWithAutoStorageDurationReadBeforeInit.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-9-1 * correctness * security + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/mandatory */ diff --git a/c/misra/src/rules/RULE-9-2/InitializerForAggregateOrUnionNotEnclosedInBraces.ql b/c/misra/src/rules/RULE-9-2/InitializerForAggregateOrUnionNotEnclosedInBraces.ql index 02ee294036..c5a9ae4814 100644 --- a/c/misra/src/rules/RULE-9-2/InitializerForAggregateOrUnionNotEnclosedInBraces.ql +++ b/c/misra/src/rules/RULE-9-2/InitializerForAggregateOrUnionNotEnclosedInBraces.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-9-2 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-9-3/PartiallyInitializedArrayWithExplicitInitializers.ql b/c/misra/src/rules/RULE-9-3/PartiallyInitializedArrayWithExplicitInitializers.ql index 231520ce50..d10c8315e1 100644 --- a/c/misra/src/rules/RULE-9-3/PartiallyInitializedArrayWithExplicitInitializers.ql +++ b/c/misra/src/rules/RULE-9-3/PartiallyInitializedArrayWithExplicitInitializers.ql @@ -9,6 +9,7 @@ * @tags external/misra/id/rule-9-3 * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-9-4/RepeatedInitializationOfAggregateObjectElement.ql b/c/misra/src/rules/RULE-9-4/RepeatedInitializationOfAggregateObjectElement.ql index 3566835ae3..4f72d6720b 100644 --- a/c/misra/src/rules/RULE-9-4/RepeatedInitializationOfAggregateObjectElement.ql +++ b/c/misra/src/rules/RULE-9-4/RepeatedInitializationOfAggregateObjectElement.ql @@ -10,6 +10,7 @@ * correctness * maintainability * readability + * external/misra/c/2012/third-edition-first-revision * external/misra/obligation/required */ diff --git a/rule_packages/c/Banned.json b/rule_packages/c/Banned.json index cab9ffc8c7..d3825f8f30 100644 --- a/rule_packages/c/Banned.json +++ b/rule_packages/c/Banned.json @@ -35,7 +35,8 @@ "short_name": "CommaOperatorShouldNotBeUsed", "shared_implementation_short_name": "CommaOperatorUsed", "tags": [ - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -54,7 +55,8 @@ "severity": "error", "short_name": "FeaturesOfStdarghUsed", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -73,7 +75,8 @@ "severity": "warning", "short_name": "UnionKeywordShouldNotBeUsed", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -92,7 +95,8 @@ "severity": "error", "short_name": "StandardLibraryTimeAndDateFunctionsUsed", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -111,7 +115,8 @@ "severity": "error", "short_name": "StandardHeaderFileTgmathhUsed", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -130,7 +135,8 @@ "severity": "warning", "short_name": "ExceptionHandlingFeaturesOfFenvhUsed", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/amendment2" ] } ], @@ -149,7 +155,8 @@ "severity": "error", "short_name": "SystemOfStdlibhUsed", "tags": [ - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -169,7 +176,8 @@ "short_name": "MemoryAllocDeallocFunctionsOfStdlibhUsed", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -188,7 +196,8 @@ "severity": "error", "short_name": "StandardHeaderFileUsedSetjmph", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -207,7 +216,8 @@ "severity": "error", "short_name": "StandardHeaderFileUsedSignalh", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -227,7 +237,8 @@ "short_name": "StandardLibraryInputoutputFunctionsUsed", "tags": [ "security", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -247,7 +258,8 @@ "short_name": "AtofAtoiAtolAndAtollOfStdlibhUsed", "shared_implementation_short_name": "AtofAtoiAtolAndAtollUsed", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -267,7 +279,8 @@ "short_name": "TerminationFunctionsOfStdlibhUsed", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -279,7 +292,8 @@ "short_name": "TerminationMacrosOfStdlibhUsed", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -299,7 +313,8 @@ "short_name": "BsearchAndQsortOfStdlibhUsed", "tags": [ "security", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -320,7 +335,8 @@ "tags": [ "security", "correctness", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -342,7 +358,8 @@ "tags": [ "readability", "correctness", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -362,7 +379,8 @@ "short_name": "RestrictTypeQualifierUsed", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/BitfieldTypes.json b/rule_packages/c/BitfieldTypes.json index 76490d73d1..43ed42f174 100644 --- a/rule_packages/c/BitfieldTypes.json +++ b/rule_packages/c/BitfieldTypes.json @@ -13,7 +13,9 @@ "severity": "error", "short_name": "BitFieldsShallOnlyBeDeclaredWithAnAppropriateType", "shared_implementation_short_name": "BitFieldShallHaveAnAppropriateType", - "tags": [] + "tags": [ + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "Bit-fields shall only be declared with an appropriate type" @@ -31,7 +33,9 @@ "severity": "error", "short_name": "SingleBitNamedBitFieldsOfASignedType", "shared_implementation_short_name": "NamedBitFieldsWithSignedIntegerType", - "tags": [] + "tags": [ + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "Single-bit named bit fields shall not be of a signed type" diff --git a/rule_packages/c/BitfieldTypes2.json b/rule_packages/c/BitfieldTypes2.json index d916421b1f..957e9bb729 100644 --- a/rule_packages/c/BitfieldTypes2.json +++ b/rule_packages/c/BitfieldTypes2.json @@ -12,7 +12,10 @@ "precision": "very-high", "severity": "warning", "short_name": "BitFieldDeclaredAsMemberOfAUnion", - "tags": ["correctness"] + "tags": [ + "correctness", + "external/misra/c/2012/amendment3" + ] } ], "title": "A bit field shall not be declared as a member of a union" diff --git a/rule_packages/c/Concurrency4.json b/rule_packages/c/Concurrency4.json index 65a17ed2d7..d537ee713e 100644 --- a/rule_packages/c/Concurrency4.json +++ b/rule_packages/c/Concurrency4.json @@ -19,14 +19,13 @@ "implementation_scope": { "description": "This query does not attempt to ensure that the deallocation function in fact deallocates memory and instead assumes the contract is valid. Additionally, this query requires that all `tss_create` calls are bookended by calls to `tss_delete`, even if a thread is not created." } - } ], "title": "Clean up thread-specific storage" }, "CON34-C": { "properties": { - "obligation": "rule" + "obligation": "rule" }, "queries": [ { @@ -54,7 +53,7 @@ "tags": [ "external/cert/audit", "correctness", - "concurrency" + "concurrency" ] } ], diff --git a/rule_packages/c/Contracts1.json b/rule_packages/c/Contracts1.json index 2882bb617f..21641922af 100644 --- a/rule_packages/c/Contracts1.json +++ b/rule_packages/c/Contracts1.json @@ -4,38 +4,42 @@ "properties": { "obligation": "rule" }, - "queries": [{ - "description": "Modification of return values of getenv and similar functions results in undefined behaviour.", - "kind": "path-problem", - "name": "Do not modify the return value of certain functions", - "precision": "very-high", - "severity": "warning", - "short_name": "DoNotModifyTheReturnValueOfCertainFunctions", - "shared_implementation_short_name": "ConstLikeReturnValue", - "tags": [ - "correctness" - ] - }], + "queries": [ + { + "description": "Modification of return values of getenv and similar functions results in undefined behaviour.", + "kind": "path-problem", + "name": "Do not modify the return value of certain functions", + "precision": "very-high", + "severity": "warning", + "short_name": "DoNotModifyTheReturnValueOfCertainFunctions", + "shared_implementation_short_name": "ConstLikeReturnValue", + "tags": [ + "correctness" + ] + } + ], "title": "Do not modify the object referenced by the return value of certain functions" }, "ENV31-C": { "properties": { "obligation": "rule" }, - "queries": [{ - "description": "Using the envp pointer after environment modifications can result in undefined behavior.", - "kind": "problem", - "name": "Do not rely on an env pointer following an operation that may invalidate it", - "precision": "high", - "severity": "error", - "short_name": "EnvPointerIsInvalidAfterCertainOperations", - "tags": [ - "correctness" - ], - "implementation_scope": { - "description": "The rule is enforced in the context of a single function." + "queries": [ + { + "description": "Using the envp pointer after environment modifications can result in undefined behavior.", + "kind": "problem", + "name": "Do not rely on an env pointer following an operation that may invalidate it", + "precision": "high", + "severity": "error", + "short_name": "EnvPointerIsInvalidAfterCertainOperations", + "tags": [ + "correctness" + ], + "implementation_scope": { + "description": "The rule is enforced in the context of a single function." + } } - }], + ], "title": "Do not rely on an environment pointer following an operation that may invalidate it" } } diff --git a/rule_packages/c/Contracts2.json b/rule_packages/c/Contracts2.json index b4845fc2be..b07f8f0503 100644 --- a/rule_packages/c/Contracts2.json +++ b/rule_packages/c/Contracts2.json @@ -67,7 +67,8 @@ "short_name": "ValuesReturnedByLocaleSettingUsedAsPtrToConst", "shared_implementation_short_name": "ConstLikeReturnValue", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -87,7 +88,8 @@ "short_name": "CallToSetlocaleInvalidatesOldPointers", "shared_implementation_short_name": "InvalidatedEnvStringPointers", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -99,7 +101,8 @@ "short_name": "CallToSetlocaleInvalidatesOldPointersWarn", "shared_implementation_short_name": "InvalidatedEnvStringPointersWarn", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Contracts3.json b/rule_packages/c/Contracts3.json index 8cb997c3b2..0122b858b5 100644 --- a/rule_packages/c/Contracts3.json +++ b/rule_packages/c/Contracts3.json @@ -4,46 +4,61 @@ "properties": { "obligation": "required" }, - "queries": [{ - "description": "The value of errno shall only be tested when the last function to be called was an errno-setting-function. Testing the value in these conditions does not guarantee the absence of an errors.", - "kind": "problem", - "name": "The value of errno shall only be tested when the last called function is errno-setting", - "precision": "high", - "severity": "warning", - "short_name": "OnlyTestErrnoRightAfterErrnoSettingFunction", - "tags": ["correctness"] - }], + "queries": [ + { + "description": "The value of errno shall only be tested when the last function to be called was an errno-setting-function. Testing the value in these conditions does not guarantee the absence of an errors.", + "kind": "problem", + "name": "The value of errno shall only be tested when the last called function is errno-setting", + "precision": "high", + "severity": "warning", + "short_name": "OnlyTestErrnoRightAfterErrnoSettingFunction", + "tags": [ + "correctness", + "external/misra/c/2012/third-edition-first-revision" + ] + } + ], "title": "The value of errno shall only be tested when the last function to be called was an errno-setting-function" }, "RULE-22-8": { "properties": { "obligation": "required" }, - "queries": [{ - "description": "The value of errno shall be set to zero prior to a call to an errno-setting-function. Not setting the value leads to incorrectly identifying errors.", - "kind": "problem", - "name": "The value of errno shall be set to zero prior to a call to an errno-setting-function", - "precision": "very-high", - "severity": "error", - "short_name": "ErrnoSetToZeroPriorToCall", - "tags": ["correctness"] - }], + "queries": [ + { + "description": "The value of errno shall be set to zero prior to a call to an errno-setting-function. Not setting the value leads to incorrectly identifying errors.", + "kind": "problem", + "name": "The value of errno shall be set to zero prior to a call to an errno-setting-function", + "precision": "very-high", + "severity": "error", + "short_name": "ErrnoSetToZeroPriorToCall", + "tags": [ + "correctness", + "external/misra/c/2012/third-edition-first-revision" + ] + } + ], "title": "The value of errno shall be set to zero prior to a call to an errno-setting-function" }, "RULE-22-9": { "properties": { "obligation": "required" }, - "queries": [{ - "description": "The value of errno shall be tested against zero after calling an errno-setting-function. Not testing the value leads to unidentified errors.", - "kind": "problem", - "name": "The value of errno shall be tested against zero after calling an errno-setting-function", - "precision": "very-high", - "severity": "error", - "short_name": "ErrnoSetToZeroAfterCall", - "tags": ["correctness"] - }], + "queries": [ + { + "description": "The value of errno shall be tested against zero after calling an errno-setting-function. Not testing the value leads to unidentified errors.", + "kind": "problem", + "name": "The value of errno shall be tested against zero after calling an errno-setting-function", + "precision": "very-high", + "severity": "error", + "short_name": "ErrnoSetToZeroAfterCall", + "tags": [ + "correctness", + "external/misra/c/2012/third-edition-first-revision" + ] + } + ], "title": "The value of errno shall be tested against zero after calling an errno-setting-function" } } -} +} \ No newline at end of file diff --git a/rule_packages/c/Contracts4.json b/rule_packages/c/Contracts4.json index 90568bec98..8ba25ab32b 100644 --- a/rule_packages/c/Contracts4.json +++ b/rule_packages/c/Contracts4.json @@ -4,22 +4,28 @@ "properties": { "obligation": "rule" }, - "queries": [{ + "queries": [ + { "description": "Do not rely solely on errno to determine if en error occurred in setlocale.", "kind": "problem", "name": "Do not rely solely on errno to determine if en error occurred in setlocale", "precision": "high", "severity": "error", "short_name": "SetlocaleMightSetErrno", - "tags": ["correctness"] - }, { + "tags": [ + "correctness" + ] + }, + { "description": "Do not check errno before the function return value. Failing to do so might invalidate the error detection.", "kind": "problem", "name": "Do not check errno before the function return value", "precision": "high", "severity": "error", "short_name": "ErrnoReadBeforeReturn", - "tags": ["correctness"] + "tags": [ + "correctness" + ] }, { "description": "After calling an errno-setting function, check errno before calling any other function. Failing to do so might end in errno being overwritten.", @@ -28,7 +34,9 @@ "precision": "high", "severity": "error", "short_name": "FunctionCallBeforeErrnoCheck", - "tags": ["correctness"] + "tags": [ + "correctness" + ] }, { "description": "Set errno to zero prior to each call to an errno-setting function. Failing to do so might end in spurious errno values.", @@ -37,7 +45,9 @@ "precision": "high", "severity": "error", "short_name": "ErrnoNotSetToZero", - "tags": ["correctness"] + "tags": [ + "correctness" + ] } ], "title": "Take care when reading errno" diff --git a/rule_packages/c/Contracts5.json b/rule_packages/c/Contracts5.json index 1032e0546e..9f62ce9255 100644 --- a/rule_packages/c/Contracts5.json +++ b/rule_packages/c/Contracts5.json @@ -4,36 +4,44 @@ "properties": { "obligation": "rule" }, - "queries": [{ - "description": "Do not rely on indeterminate values of errno. This may result in undefined behavior.", - "kind": "problem", - "name": "Do not rely on indeterminate values of errno", - "precision": "high", - "severity": "error", - "short_name": "DoNotRelyOnIndeterminateValuesOfErrno", - "tags": ["correctness"], - "implementation_scope": { - "description": "The rule is enforced in the context of a single function." + "queries": [ + { + "description": "Do not rely on indeterminate values of errno. This may result in undefined behavior.", + "kind": "problem", + "name": "Do not rely on indeterminate values of errno", + "precision": "high", + "severity": "error", + "short_name": "DoNotRelyOnIndeterminateValuesOfErrno", + "tags": [ + "correctness" + ], + "implementation_scope": { + "description": "The rule is enforced in the context of a single function." + } } - }], + ], "title": "Do not rely on indeterminate values of errno" }, "ERR33-C": { "properties": { "obligation": "rule" }, - "queries": [{ - "description": "Detect and handle standard library errors. Undetected failures can lead to unexpected or undefined behavior.", - "kind": "problem", - "name": "Detect and handle standard library errors", - "precision": "high", - "severity": "error", - "short_name": "DetectAndHandleStandardLibraryErrors", - "tags": ["correctness"], - "implementation_scope": { - "description": "The rule is enforced in the context of a single function." + "queries": [ + { + "description": "Detect and handle standard library errors. Undetected failures can lead to unexpected or undefined behavior.", + "kind": "problem", + "name": "Detect and handle standard library errors", + "precision": "high", + "severity": "error", + "short_name": "DetectAndHandleStandardLibraryErrors", + "tags": [ + "correctness" + ], + "implementation_scope": { + "description": "The rule is enforced in the context of a single function." + } } - }], + ], "title": "Detect and handle standard library errors" } } diff --git a/rule_packages/c/Contracts6.json b/rule_packages/c/Contracts6.json index bc707f19f4..4dbae7e121 100644 --- a/rule_packages/c/Contracts6.json +++ b/rule_packages/c/Contracts6.json @@ -12,7 +12,9 @@ "precision": "high", "severity": "error", "short_name": "DoNotModifyConstantObjects", - "tags": ["correctness"], + "tags": [ + "correctness" + ], "implementation_scope": { "description": "The implementation does not consider pointer aliasing via multiple indirection." } @@ -34,7 +36,10 @@ "precision": "high", "severity": "error", "short_name": "ArrayFunctionArgumentNumberOfElements", - "tags": ["correctness"] + "tags": [ + "correctness", + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "The function argument corresponding to an array parameter shall have an appropriate number of elements" @@ -51,7 +56,10 @@ "precision": "very-high", "severity": "error", "short_name": "ValueReturnedByAFunctionNotUsed", - "tags": ["correctness"] + "tags": [ + "correctness", + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "The value returned by a function having non-void return type shall be used or cast to void" diff --git a/rule_packages/c/Contracts7.json b/rule_packages/c/Contracts7.json index 38a038621e..f76b737db1 100644 --- a/rule_packages/c/Contracts7.json +++ b/rule_packages/c/Contracts7.json @@ -54,7 +54,8 @@ "severity": "error", "short_name": "RightHandOperandOfAShiftRange", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -73,7 +74,8 @@ "severity": "error", "short_name": "ObjectAssignedToAnOverlappingObject", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -84,7 +86,8 @@ "severity": "error", "short_name": "ObjectCopiedToAnOverlappingObject", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/DeadCode.json b/rule_packages/c/DeadCode.json index 1de7625225..ea5ddad703 100644 --- a/rule_packages/c/DeadCode.json +++ b/rule_packages/c/DeadCode.json @@ -14,7 +14,8 @@ "short_name": "UnreachableCode", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query reports basic blocks in the program which are unreachable. For basic blocks within templates, the block is only consider unreachable if it is unreachable in all templates. Code generated by macros is ignored for this query, because it may be the case that basic blocks are reachable only in some expansions." @@ -38,7 +39,8 @@ "short_name": "DeadCode", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query identifies dead statements in the program of the following kinds:", @@ -72,7 +74,8 @@ "short_name": "UnusedTypeDeclarations", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ], "shared_implementation_short_name": "UnusedTypeDeclarations" } @@ -93,7 +96,8 @@ "short_name": "UnusedTagDeclaration", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -113,7 +117,8 @@ "short_name": "UnusedMacroDeclaration", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -133,7 +138,8 @@ "short_name": "UnusedLabelDeclaration", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -153,7 +159,8 @@ "short_name": "UnusedParameter", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ], "shared_implementation_short_name": "UnusedParameter" } diff --git a/rule_packages/c/Declarations1.json b/rule_packages/c/Declarations1.json index 217e1e077c..90202a5b52 100644 --- a/rule_packages/c/Declarations1.json +++ b/rule_packages/c/Declarations1.json @@ -1,56 +1,56 @@ { "CERT-C": { "DCL31-C": { - "properties": { - "obligation": "rule" - }, - "queries": [ - { - "description": "Omission of type specifiers may not be supported by some compilers.", - "kind": "problem", - "name": "Declare identifiers before using them", - "precision": "very-high", - "severity": "error", - "short_name": "DeclareIdentifiersBeforeUsingThem", - "shared_implementation_short_name": "TypeOmitted", - "tags": [ - "correctness", - "readability" - ], - "implementation_scope": { - "description": "This query does not check for implicitly typed parameters, typedefs or member declarations as this is partially compiler checked.", - "items": [] - } + "properties": { + "obligation": "rule" + }, + "queries": [ + { + "description": "Omission of type specifiers may not be supported by some compilers.", + "kind": "problem", + "name": "Declare identifiers before using them", + "precision": "very-high", + "severity": "error", + "short_name": "DeclareIdentifiersBeforeUsingThem", + "shared_implementation_short_name": "TypeOmitted", + "tags": [ + "correctness", + "readability" + ], + "implementation_scope": { + "description": "This query does not check for implicitly typed parameters, typedefs or member declarations as this is partially compiler checked.", + "items": [] } - ], - "title": "Declare identifiers before using them" + } + ], + "title": "Declare identifiers before using them" + }, + "DCL37-C": { + "properties": { + "obligation": "rule" }, - "DCL37-C": { - "properties": { - "obligation": "rule" - }, - "queries": [ - { - "description": "Declaring a reserved identifier can lead to undefined behaviour.", - "kind": "problem", - "name": "Do not declare or define a reserved identifier", - "precision": "very-high", - "severity": "warning", - "short_name": "DoNotDeclareOrDefineAReservedIdentifier", - "shared_implementation_short_name": "DeclaredAReservedIdentifier", - "tags": [ - "correctness", - "maintainability", - "readability" - ], - "implementation_scope": { - "description": "This query does not consider identifiers described in the future library directions section of the standard. This query also checks for any reserved identifier as declared regardless of whether its header file is included or not.", - "items": [] - } + "queries": [ + { + "description": "Declaring a reserved identifier can lead to undefined behaviour.", + "kind": "problem", + "name": "Do not declare or define a reserved identifier", + "precision": "very-high", + "severity": "warning", + "short_name": "DoNotDeclareOrDefineAReservedIdentifier", + "shared_implementation_short_name": "DeclaredAReservedIdentifier", + "tags": [ + "correctness", + "maintainability", + "readability" + ], + "implementation_scope": { + "description": "This query does not consider identifiers described in the future library directions section of the standard. This query also checks for any reserved identifier as declared regardless of whether its header file is included or not.", + "items": [] } - ], - "title": "Do not declare or define a reserved identifier" - } + } + ], + "title": "Do not declare or define a reserved identifier" + } }, "MISRA-C-2012": { "RULE-21-2": { @@ -69,7 +69,8 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -91,7 +92,8 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query considers the first 31 characters of identifiers as significant, as per C99 and reports the case when names are longer than 31 characters and differ in those characters past the 31 first only. This query does not consider universal or extended source characters.", @@ -102,41 +104,43 @@ "title": "External identifiers shall be distinct" }, "RULE-5-4": { - "properties": { - "obligation": "required" + "properties": { + "obligation": "required" + }, + "queries": [ + { + "description": "Declaring multiple macros with the same name leads to undefined behaviour.", + "kind": "problem", + "name": "Macro identifiers shall be distinct", + "precision": "very-high", + "severity": "warning", + "short_name": "MacroIdentifiersNotDistinct", + "tags": [ + "correctness", + "maintainability", + "readability", + "external/misra/c/2012/third-edition-first-revision" + ], + "implementation_scope": { + "description": "This query checks the first 63 characters of macro identifiers as significant, as per C99. Distinctness of parameters within the same function like macro are checked by compiler and therefore not checked by this rule.", + "items": [] + } }, - "queries": [ - { - "description": "Declaring multiple macros with the same name leads to undefined behaviour.", - "kind": "problem", - "name": "Macro identifiers shall be distinct", - "precision": "very-high", - "severity": "warning", - "short_name": "MacroIdentifiersNotDistinct", - "tags": [ - "correctness", - "maintainability", - "readability" - ], - "implementation_scope": { - "description": "This query checks the first 63 characters of macro identifiers as significant, as per C99. Distinctness of parameters within the same function like macro are checked by compiler and therefore not checked by this rule.", - "items": [] - } - }, - { - "description": "Macros with the same name as their parameters are less readable.", - "kind": "problem", - "name": "Macro identifiers shall be distinct from paramters", - "precision": "very-high", - "severity": "warning", - "short_name": "MacroIdentifierNotDistinctFromParameter", - "tags": [ - "maintainability", - "readability" - ] - } - ], - "title": "Macro identifiers shall be distinct" - } + { + "description": "Macros with the same name as their parameters are less readable.", + "kind": "problem", + "name": "Macro identifiers shall be distinct from paramters", + "precision": "very-high", + "severity": "warning", + "short_name": "MacroIdentifierNotDistinctFromParameter", + "tags": [ + "maintainability", + "readability", + "external/misra/c/2012/third-edition-first-revision" + ] + } + ], + "title": "Macro identifiers shall be distinct" + } } } \ No newline at end of file diff --git a/rule_packages/c/Declarations2.json b/rule_packages/c/Declarations2.json index 303965b6b6..9acb117d1e 100644 --- a/rule_packages/c/Declarations2.json +++ b/rule_packages/c/Declarations2.json @@ -1,98 +1,98 @@ { "CERT-C": { "DCL38-C": { - "properties": { - "obligation": "rule" - }, - "queries": [ - { - "description": "Structures with flexible array members can be declared in ways that will lead to undefined behaviour.", - "kind": "problem", - "name": "Use the correct syntax when declaring a flexible array member", - "precision": "very-high", - "severity": "error", - "short_name": "DeclaringAFlexibleArrayMember", - "tags": [ - "correctness", - "maintainability", - "readability" - ] - } - ], - "title": "Use the correct syntax when declaring a flexible array member" + "properties": { + "obligation": "rule" }, + "queries": [ + { + "description": "Structures with flexible array members can be declared in ways that will lead to undefined behaviour.", + "kind": "problem", + "name": "Use the correct syntax when declaring a flexible array member", + "precision": "very-high", + "severity": "error", + "short_name": "DeclaringAFlexibleArrayMember", + "tags": [ + "correctness", + "maintainability", + "readability" + ] + } + ], + "title": "Use the correct syntax when declaring a flexible array member" + }, "DCL40-C": { "properties": { "obligation": "rule" }, "queries": [ { - "description": "Using nondistinct external identifiers results in undefined behaviour.", - "kind": "problem", - "name": "External identifiers shall be distinct", - "precision": "very-high", - "severity": "warning", - "short_name": "ExcessLengthNamesIdentifiersNotDistinct", - "shared_implementation_short_name": "NotDistinctIdentifier", - "tags": [ - "correctness", - "maintainability", - "readability" - ], - "implementation_scope": { - "description": "This query considers the first 31 characters of identifiers as significant, as per C99 and reports the case when names are longer than 31 characters and differ in those characters past the 31 first only. This query does not consider universal or extended source characters.", - "items": [] - } - }, - { - "description": "Declaring incompatible objects, in other words same named objects of different types, then accessing those objects can lead to undefined behaviour.", - "kind": "problem", - "name": "Do not create incompatible declarations of the same function or object", - "precision": "high", - "severity": "error", - "short_name": "IncompatibleObjectDeclarations", - "tags": [ - "correctness", - "maintainability", - "readability" - ] - }, - { - "description": "Declaring incompatible functions, in other words same named function of different return types or with different numbers of parameters or parameter types, then accessing those functions can lead to undefined behaviour.", - "kind": "problem", - "name": "Do not create incompatible declarations of the same function or object", - "precision": "high", - "severity": "error", - "short_name": "IncompatibleFunctionDeclarations", - "tags": [ - "correctness", - "maintainability", - "readability" - ] + "description": "Using nondistinct external identifiers results in undefined behaviour.", + "kind": "problem", + "name": "External identifiers shall be distinct", + "precision": "very-high", + "severity": "warning", + "short_name": "ExcessLengthNamesIdentifiersNotDistinct", + "shared_implementation_short_name": "NotDistinctIdentifier", + "tags": [ + "correctness", + "maintainability", + "readability" + ], + "implementation_scope": { + "description": "This query considers the first 31 characters of identifiers as significant, as per C99 and reports the case when names are longer than 31 characters and differ in those characters past the 31 first only. This query does not consider universal or extended source characters.", + "items": [] } + }, + { + "description": "Declaring incompatible objects, in other words same named objects of different types, then accessing those objects can lead to undefined behaviour.", + "kind": "problem", + "name": "Do not create incompatible declarations of the same function or object", + "precision": "high", + "severity": "error", + "short_name": "IncompatibleObjectDeclarations", + "tags": [ + "correctness", + "maintainability", + "readability" + ] + }, + { + "description": "Declaring incompatible functions, in other words same named function of different return types or with different numbers of parameters or parameter types, then accessing those functions can lead to undefined behaviour.", + "kind": "problem", + "name": "Do not create incompatible declarations of the same function or object", + "precision": "high", + "severity": "error", + "short_name": "IncompatibleFunctionDeclarations", + "tags": [ + "correctness", + "maintainability", + "readability" + ] + } ], "title": "Do not create incompatible declarations of the same function or object" }, "DCL41-C": { - "properties": { - "obligation": "rule" - }, - "queries": [ - { - "description": "Declaring a variable in a switch statement before the first case label can result in reading uninitialized memory which is undefined behaviour.", - "kind": "problem", - "name": "Do not declare variables inside a switch statement before the first case label", - "precision": "very-high", - "severity": "error", - "short_name": "VariablesInsideSwitchStatement", - "tags": [ - "correctness", - "maintainability", - "readability" - ] - } - ], - "title": "Do not declare variables inside a switch statement before the first case label" - } + "properties": { + "obligation": "rule" + }, + "queries": [ + { + "description": "Declaring a variable in a switch statement before the first case label can result in reading uninitialized memory which is undefined behaviour.", + "kind": "problem", + "name": "Do not declare variables inside a switch statement before the first case label", + "precision": "very-high", + "severity": "error", + "short_name": "VariablesInsideSwitchStatement", + "tags": [ + "correctness", + "maintainability", + "readability" + ] + } + ], + "title": "Do not declare variables inside a switch statement before the first case label" + } } } \ No newline at end of file diff --git a/rule_packages/c/Declarations3.json b/rule_packages/c/Declarations3.json index a22567b237..8c2e0879ff 100644 --- a/rule_packages/c/Declarations3.json +++ b/rule_packages/c/Declarations3.json @@ -14,7 +14,8 @@ "shared_implementation_short_name": "IdentifierHidden", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query does not consider C90 or C99 definitions of significant name and instead uses full name matches only.", @@ -38,7 +39,8 @@ "short_name": "IdentifiersNotDistinctFromMacroNames", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -58,7 +60,8 @@ "short_name": "TypedefNameNotUnique", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -78,7 +81,8 @@ "short_name": "TagNameNotUnique", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -99,7 +103,8 @@ "shared_implementation_short_name": "TypeOmitted", "tags": [ "correctness", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query does not check for implicitly typed parameters, typedefs or member declarations as this is partially compiler checked.", diff --git a/rule_packages/c/Declarations4.json b/rule_packages/c/Declarations4.json index bfd0b18328..06475706f4 100644 --- a/rule_packages/c/Declarations4.json +++ b/rule_packages/c/Declarations4.json @@ -13,7 +13,8 @@ "severity": "error", "short_name": "FunctionTypesNotInPrototypeForm", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query does not check for implicitly typed parameters and checks function declarations and definitions but not function pointer types. This query cannot determine when the keyword void is used in place of no parameter.", @@ -36,7 +37,8 @@ "severity": "error", "short_name": "DeclarationsOfAnObjectSameNameAndType", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -47,7 +49,8 @@ "severity": "error", "short_name": "DeclarationsOfAFunctionSameNameAndType", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -68,7 +71,8 @@ "tags": [ "readability", "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query does not check for the recommendation of declarations in headers.", @@ -85,7 +89,8 @@ "tags": [ "readability", "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query does not check for the recommendation of declarations in headers.", @@ -109,7 +114,8 @@ "short_name": "IdentifierWithExternalLinkageOneDefinition", "shared_implementation_short_name": "IdentifierWithExternalLinkageOneDefinitionShared", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Declarations5.json b/rule_packages/c/Declarations5.json index 705f72791c..1106a1d705 100644 --- a/rule_packages/c/Declarations5.json +++ b/rule_packages/c/Declarations5.json @@ -15,7 +15,8 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query considers the first 63 characters of identifiers as significant, as per C99 for nonexternal identifiers and reports the case when names are longer than 63 characters and differ in those characters past the 63 first only. This query does not consider universal or extended source characters.", @@ -38,7 +39,8 @@ "severity": "warning", "short_name": "ExternalObjectOrFunctionNotDeclaredInOneFile", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -58,7 +60,8 @@ "short_name": "MissingStaticSpecifierFunctionRedeclarationC", "shared_implementation_short_name": "MissingStaticSpecifierFunctionRedeclarationShared", "tags": [ - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -69,7 +72,8 @@ "severity": "warning", "short_name": "MissingStaticSpecifierObjectRedeclarationC", "tags": [ - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -89,7 +93,8 @@ "short_name": "UnnecessaryExposedIdentifierDeclarationC", "shared_implementation_short_name": "UnnecessaryExposedIdentifierDeclarationShared", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Declarations6.json b/rule_packages/c/Declarations6.json index 166d0c568b..198b4e8351 100644 --- a/rule_packages/c/Declarations6.json +++ b/rule_packages/c/Declarations6.json @@ -14,7 +14,8 @@ "short_name": "FunctionDeclaredImplicitly", "tags": [ "correctness", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -33,7 +34,8 @@ "severity": "error", "short_name": "FlexibleArrayMembersDeclared", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -53,7 +55,8 @@ "short_name": "IdentifiersWithExternalLinkageNotUnique", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -73,7 +76,8 @@ "short_name": "IdentifiersWithInternalLinkageNotUnique", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This rule does not explicitly check for the exception of inline functions in header files across multiple translation units as the CodeQL database already represents these as the same entity." @@ -95,7 +99,8 @@ "severity": "error", "short_name": "InlineFunctionNotDeclaredStaticStorage", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -115,7 +120,8 @@ "short_name": "ArrayExternalLinkageSizeExplicitlySpecified", "tags": [ "correctness", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -136,7 +142,8 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Declarations7.json b/rule_packages/c/Declarations7.json index b1be4f9d55..cdb74123b1 100644 --- a/rule_packages/c/Declarations7.json +++ b/rule_packages/c/Declarations7.json @@ -39,7 +39,8 @@ "short_name": "VariableLengthArrayTypesUsed", "tags": [ "correctness", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -60,7 +61,8 @@ "shared_implementation_short_name": "NonUniqueEnumerationConstant", "tags": [ "correctness", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/EssentialTypes.json b/rule_packages/c/EssentialTypes.json index 57c7ace1ba..a8ae26e8c6 100644 --- a/rule_packages/c/EssentialTypes.json +++ b/rule_packages/c/EssentialTypes.json @@ -13,7 +13,8 @@ "severity": "warning", "short_name": "OperandsOfAnInappropriateEssentialType", "tags": [ - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -24,7 +25,8 @@ "severity": "warning", "short_name": "PointerTypeOnLogicalOperator", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -44,7 +46,8 @@ "short_name": "AdditionSubtractionOnEssentiallyCharType", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -64,7 +67,8 @@ "short_name": "AssignmentOfIncompatibleEssentialType", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -84,7 +88,8 @@ "short_name": "OperandsWithMismatchedEssentialTypeCategory", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -104,7 +109,8 @@ "short_name": "InappropriateEssentialTypeCast", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -124,7 +130,8 @@ "short_name": "AssignmentToWiderEssentialType", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -144,7 +151,8 @@ "short_name": "ImplicitConversionOfCompositeExpression", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -164,7 +172,8 @@ "short_name": "InappropriateCastOfCompositeExpression", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -184,7 +193,8 @@ "short_name": "LoopOverEssentiallyFloatType", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -204,7 +214,8 @@ "short_name": "MemcmpUsedToCompareNullTerminatedStrings", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -224,7 +235,8 @@ "short_name": "MemcmpOnInappropriateEssentialTypeArgs", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/IO1.json b/rule_packages/c/IO1.json index 1d90c6f28f..f5b9ec8b0e 100644 --- a/rule_packages/c/IO1.json +++ b/rule_packages/c/IO1.json @@ -145,7 +145,8 @@ "short_name": "FileUsedAfterClosed", "shared_implementation_short_name": "DoNotAccessAClosedFile", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "The rule is enforced in the context of a single function." diff --git a/rule_packages/c/IO3.json b/rule_packages/c/IO3.json index 8d1c250eda..52276eb05c 100644 --- a/rule_packages/c/IO3.json +++ b/rule_packages/c/IO3.json @@ -60,7 +60,8 @@ "severity": "error", "short_name": "FileOpenForReadAndWriteOnDifferentStreams", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "The rule is enforced in the context of a single function." @@ -82,7 +83,8 @@ "severity": "error", "short_name": "AttemptToWriteToAReadOnlyStream", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -101,7 +103,8 @@ "severity": "error", "short_name": "PointerToAFileObjectDereferenced", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -120,7 +123,8 @@ "severity": "error", "short_name": "EofShallBeComparedWithUnmodifiedReturnValues", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/IO4.json b/rule_packages/c/IO4.json index 0873d2707b..1303f9b50f 100644 --- a/rule_packages/c/IO4.json +++ b/rule_packages/c/IO4.json @@ -68,4 +68,4 @@ "title": "Use valid format strings" } } -} +} \ No newline at end of file diff --git a/rule_packages/c/IntegerOverflow.json b/rule_packages/c/IntegerOverflow.json index 0fb1c5a4e7..a7897fad9e 100644 --- a/rule_packages/c/IntegerOverflow.json +++ b/rule_packages/c/IntegerOverflow.json @@ -115,7 +115,8 @@ "shared_implementation_short_name": "ConstantUnsignedIntegerExpressionsWrapAround", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/InvalidMemory1.json b/rule_packages/c/InvalidMemory1.json index 0d84c1c87e..227ec37558 100644 --- a/rule_packages/c/InvalidMemory1.json +++ b/rule_packages/c/InvalidMemory1.json @@ -78,7 +78,8 @@ "short_name": "ObjectWithAutoStorageDurationReadBeforeInit", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Language1.json b/rule_packages/c/Language1.json index 50aed45c55..6b20822196 100644 --- a/rule_packages/c/Language1.json +++ b/rule_packages/c/Language1.json @@ -14,7 +14,8 @@ "short_name": "LanguageNotEncapsulatedAndIsolated", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Language2.json b/rule_packages/c/Language2.json index 66f219a025..43dbb4ecef 100644 --- a/rule_packages/c/Language2.json +++ b/rule_packages/c/Language2.json @@ -15,7 +15,8 @@ "shared_implementation_short_name": "UsageOfAssemblerNotDocumented", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -35,7 +36,8 @@ "short_name": "EmergentLanguageFeaturesUsed", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/amendment2" ] } ], diff --git a/rule_packages/c/Language3.json b/rule_packages/c/Language3.json index d48444a4ab..c19881e05c 100644 --- a/rule_packages/c/Language3.json +++ b/rule_packages/c/Language3.json @@ -14,7 +14,8 @@ "short_name": "LanguageExtensionsShouldNotBeUsed", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This implementation attempts to cover a broad section of the compiler specific extensions documented in: https://clang.llvm.org/docs/LanguageExtensions.html and https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html but is not comprehensive. The following topics are addressed in this query: Builtin macros, Variable Attributes, Function Attributes, Statement Expressions, Non-Local Gotos, Conditionals, Extended Integer / Numeric Types, Zero Length Structures, Zero Length Arrays, Variable Length Arrays, Case Attributes, Alignment, __sync and __fetch builtins. Other topics listed in the extension references are not covered by this query." @@ -37,7 +38,8 @@ "short_name": "OccurrenceOfUndefinedBehavior", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This implementation only considers alternate forms of `main` and the undefined behavior that results. Note that the current version of CodeQL is not able to detect this issue if a function is named `main` since it will assume the return type and formal parameters. Additional cases from Appendix J of the C99 standard are not currently considered." diff --git a/rule_packages/c/Memory1.json b/rule_packages/c/Memory1.json index 7232b18751..8515fe15e1 100644 --- a/rule_packages/c/Memory1.json +++ b/rule_packages/c/Memory1.json @@ -14,8 +14,9 @@ "short_name": "InitializerForAggregateOrUnionNotEnclosedInBraces", "shared_implementation_short_name": "UseInitializerBracesToMatchAggregateTypeStructure", "tags": [ - "maintainability", - "readability" + "maintainability", + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -35,7 +36,8 @@ "short_name": "PartiallyInitializedArrayWithExplicitInitializers", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -56,7 +58,8 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Memory2.json b/rule_packages/c/Memory2.json index 677711938a..358d482194 100644 --- a/rule_packages/c/Memory2.json +++ b/rule_packages/c/Memory2.json @@ -164,7 +164,8 @@ "shared_implementation_short_name": "FreeMemoryWhenNoLongerNeededShared", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "The rule is enforced in the context of a single function." @@ -180,7 +181,8 @@ "shared_implementation_short_name": "CloseFileHandleWhenNoLongerNeededShared", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "The rule is enforced in the context of a single function." @@ -204,7 +206,8 @@ "shared_implementation_short_name": "OnlyFreeMemoryAllocatedDynamicallyShared", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Misc.json b/rule_packages/c/Misc.json index 323ec17350..bba96db85c 100644 --- a/rule_packages/c/Misc.json +++ b/rule_packages/c/Misc.json @@ -12,7 +12,7 @@ "precision": "very-high", "severity": "error", "short_name": "RandUsedForGeneratingPseudorandomNumbers", - "shared_implementation_short_name" : "DoNotUseRandForGeneratingPseudorandomNumbers", + "shared_implementation_short_name": "DoNotUseRandForGeneratingPseudorandomNumbers", "tags": [ "security" ] diff --git a/rule_packages/c/OutOfBounds.json b/rule_packages/c/OutOfBounds.json index 31d0349a63..759b68e294 100644 --- a/rule_packages/c/OutOfBounds.json +++ b/rule_packages/c/OutOfBounds.json @@ -56,7 +56,8 @@ "short_name": "StringFunctionPointerArgumentOutOfBounds", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -76,7 +77,8 @@ "short_name": "StringLibrarySizeArgumentOutOfBounds", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Pointers1.json b/rule_packages/c/Pointers1.json index 6b2df1595c..29b658d823 100644 --- a/rule_packages/c/Pointers1.json +++ b/rule_packages/c/Pointers1.json @@ -13,7 +13,8 @@ "severity": "error", "short_name": "ConversionBetweenFunctionPointerAndOtherType", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -32,7 +33,8 @@ "severity": "error", "short_name": "ConversionBetweenIncompleteTypePointerAndOtherType", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -51,7 +53,8 @@ "severity": "error", "short_name": "CastBetweenObjectPointerAndDifferentObjectType", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -70,7 +73,8 @@ "severity": "error", "short_name": "ConversionBetweenPointerToObjectAndIntegerType", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -89,7 +93,8 @@ "severity": "error", "short_name": "ConversionFromPointerToVoidIntoPointerToObject", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -108,7 +113,8 @@ "severity": "error", "short_name": "CastBetweenPointerToVoidAndArithmeticType", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -127,7 +133,8 @@ "severity": "error", "short_name": "CastBetweenPointerToObjectAndNonIntArithmeticType", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -146,7 +153,8 @@ "severity": "error", "short_name": "CastRemovesConstOrVolatileQualification", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -165,7 +173,8 @@ "severity": "error", "short_name": "MacroNullNotUsedAsIntegerNullPointerConstant", "tags": [ - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This rule allows two forms of null-pointer constants: a Zero literal created by the NULL macro or a Zero literal cast to a void pointer." @@ -188,7 +197,8 @@ "short_name": "PointerAndDerivedPointerMustAddressSameArray", "shared_implementation_short_name": "DoNotUsePointerArithmeticToAddressDifferentArrays", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -208,7 +218,8 @@ "short_name": "SubtractionBetweenPointersMustAddressSameArray", "shared_implementation_short_name": "DoNotSubtractPointersAddressingDifferentArrays", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -228,7 +239,8 @@ "short_name": "RelationalOperatorComparesPointerToDifferentArray", "shared_implementation_short_name": "DoNotUseRelationalOperatorsWithDifferingArrays", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -248,7 +260,8 @@ "short_name": "DoNotUseAdditionOrSubtractionOperatorsOnPointers", "shared_implementation_short_name": "UseOnlyArrayIndexingForPointerArithmetic", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -268,7 +281,8 @@ "short_name": "NoMoreThanTwoLevelsOfPointerNestingInDeclarations", "shared_implementation_short_name": "DoNotUseMoreThanTwoLevelsOfPointerIndirection", "tags": [ - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -288,7 +302,8 @@ "short_name": "AutomaticStorageObjectAddressCopiedToOtherObject", "shared_implementation_short_name": "DoNotCopyAddressOfAutoStorageObjectToOtherObject", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -308,7 +323,8 @@ "short_name": "ObjectWithNoPointerDereferenceShouldBeOpaque", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This rule considers all cases where a structure or union is referenced as a pointer but has no FieldAccess within a translation unit. Further excluded from this rule are translation units in which the structure or union is declared as a non-pointer variable." @@ -332,7 +348,8 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "To exclude compliant exceptions, this rule only excludes direct assignments of pointers to non-const-qualified types in the context of a single function and does not cover memory-copying functions. This rule also excludes pointers passed to other functions without conversion." diff --git a/rule_packages/c/Pointers2.json b/rule_packages/c/Pointers2.json index da275001c4..9abf4c98ce 100644 --- a/rule_packages/c/Pointers2.json +++ b/rule_packages/c/Pointers2.json @@ -12,7 +12,7 @@ "precision": "high", "severity": "error", "short_name": "DoNotAddOrSubtractAScaledIntegerToAPointer", - "tags":[ + "tags": [ "correctness" ] } diff --git a/rule_packages/c/Preprocessor1.json b/rule_packages/c/Preprocessor1.json index b93bc72731..cf4f023023 100644 --- a/rule_packages/c/Preprocessor1.json +++ b/rule_packages/c/Preprocessor1.json @@ -14,7 +14,8 @@ "short_name": "IncludeDirectivesPrecededByDirectivesOrComments", "shared_implementation_short_name": "PreprocessorIncludesPreceded", "tags": [ - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -34,10 +35,10 @@ "short_name": "PreprocessorHashOperatorsShouldNotBeUsed", "shared_implementation_short_name": "HashOperatorsUsed", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } - ], "title": "The # and ## preprocessor operators should not be used" }, @@ -55,7 +56,8 @@ "short_name": "ForbiddenCharactersInHeaderFileName", "shared_implementation_short_name": "PreprocessorIncludesForbiddenHeaderNames", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query identifies the use of the ', \\, /*, // characters in header file names. The query is not able to detect the use of the \" character in header file names.", @@ -79,8 +81,9 @@ "short_name": "IdentifiersUsedInPreprocessorExpression", "shared_implementation_short_name": "UndefinedMacroIdentifiers", "tags": [ - "correctness", - "readability" + "correctness", + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query does not detect the case where an undefined character is used but not actually evaluated, for example, as a result of the inclusion of a logical AND operator in the #if expression.", diff --git a/rule_packages/c/Preprocessor2.json b/rule_packages/c/Preprocessor2.json index 546f426135..62bb0b770a 100644 --- a/rule_packages/c/Preprocessor2.json +++ b/rule_packages/c/Preprocessor2.json @@ -14,7 +14,8 @@ "short_name": "MoreThanOneHashOperatorInMacroDefinition", "shared_implementation_short_name": "MacroParameterFollowingHash", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query applies to function like macros and not object like macros. This rule strictly disallows the use of # operator followed by a ## and other combinations are permitted.", @@ -39,7 +40,8 @@ "shared_implementation_short_name": "AMixedUseMacroArgumentSubjectToExpansion", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -59,7 +61,8 @@ "short_name": "UndefShouldNotBeUsed", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -81,7 +84,8 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query defines header file as any file that is included regardless of file extension. This query does not consider the use of `#pragma once` as a permitted header guard.", diff --git a/rule_packages/c/Preprocessor3.json b/rule_packages/c/Preprocessor3.json index 0b0c735a04..79e2aec59c 100644 --- a/rule_packages/c/Preprocessor3.json +++ b/rule_packages/c/Preprocessor3.json @@ -1,24 +1,25 @@ { "MISRA-C-2012": { "RULE-20-8": { - "properties": { - "obligation": "required" - }, - "queries": [ - { - "description": "A controlling expression of a #if or #elif preprocessing directive that does not evaluate to 0 or 1 makes code more difficult to understand.", - "kind": "problem", - "name": "The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1", - "precision": "high", - "severity": "warning", - "short_name": "ControllingExpressionIfDirective", - "tags": [ - "maintainability", - "readability" - ] - } - ], - "title": "The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1" - } + "properties": { + "obligation": "required" + }, + "queries": [ + { + "description": "A controlling expression of a #if or #elif preprocessing directive that does not evaluate to 0 or 1 makes code more difficult to understand.", + "kind": "problem", + "name": "The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1", + "precision": "high", + "severity": "warning", + "short_name": "ControllingExpressionIfDirective", + "tags": [ + "maintainability", + "readability", + "external/misra/c/2012/third-edition-first-revision" + ] + } + ], + "title": "The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1" + } } } \ No newline at end of file diff --git a/rule_packages/c/Preprocessor4.json b/rule_packages/c/Preprocessor4.json index 404909c479..608a23d974 100644 --- a/rule_packages/c/Preprocessor4.json +++ b/rule_packages/c/Preprocessor4.json @@ -15,7 +15,8 @@ "tags": [ "correctness", "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -36,7 +37,8 @@ "shared_implementation_short_name": "PreprocessingDirectiveWithinMacroArgument", "tags": [ "readability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -57,7 +59,8 @@ "tags": [ "correctness", "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Preprocessor5.json b/rule_packages/c/Preprocessor5.json index 29c0156410..ef17b83c00 100644 --- a/rule_packages/c/Preprocessor5.json +++ b/rule_packages/c/Preprocessor5.json @@ -65,7 +65,8 @@ "shared_implementation_short_name": "MacroParameterNotEnclosedInParentheses", "tags": [ "correctness", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This query checks for every instance of a parameter to be enclosed in parentheses regardless of whether the expansion of that parameter forms an expression or not.", diff --git a/rule_packages/c/Preprocessor6.json b/rule_packages/c/Preprocessor6.json index 0bb7f34f90..6d71b8697b 100644 --- a/rule_packages/c/Preprocessor6.json +++ b/rule_packages/c/Preprocessor6.json @@ -16,7 +16,8 @@ "tags": [ "external/misra/audit", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/SideEffects1.json b/rule_packages/c/SideEffects1.json index 821fb24d3c..9ecb79447d 100644 --- a/rule_packages/c/SideEffects1.json +++ b/rule_packages/c/SideEffects1.json @@ -83,7 +83,8 @@ "severity": "warning", "short_name": "UnenclosedSizeofOperand", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -94,7 +95,8 @@ "severity": "warning", "short_name": "ImplicitPrecedenceOfOperatorsInExpression", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -113,7 +115,8 @@ "severity": "error", "short_name": "InitializerListsContainPersistentSideEffects", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -134,7 +137,8 @@ "shared_implementation_short_name": "ResultOfAnAssignmentOperatorShouldNotBeUsed", "tags": [ "correctness", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -153,7 +157,8 @@ "severity": "error", "short_name": "PossibleSuppressedSideEffectInLogicOperatorOperand", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -172,7 +177,8 @@ "severity": "error", "short_name": "SizeofOperandWithSideEffect", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/SideEffects2.json b/rule_packages/c/SideEffects2.json index 42467c2852..b7e1baa901 100644 --- a/rule_packages/c/SideEffects2.json +++ b/rule_packages/c/SideEffects2.json @@ -14,7 +14,8 @@ "short_name": "SideEffectAndCrementInFullExpression", "tags": [ "readability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -33,7 +34,8 @@ "severity": "warning", "short_name": "ModificationOfFunctionParameter", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/SideEffects3.json b/rule_packages/c/SideEffects3.json index 2d67df6e2e..2bf91d77b9 100644 --- a/rule_packages/c/SideEffects3.json +++ b/rule_packages/c/SideEffects3.json @@ -13,7 +13,8 @@ "severity": "error", "short_name": "UnsequencedSideEffects", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/StandardLibraryFunctionTypes.json b/rule_packages/c/StandardLibraryFunctionTypes.json index 274eadbced..ee0d7f5af1 100644 --- a/rule_packages/c/StandardLibraryFunctionTypes.json +++ b/rule_packages/c/StandardLibraryFunctionTypes.json @@ -12,7 +12,9 @@ "precision": "very-high", "severity": "error", "short_name": "CtypeFunctionArgNotUnsignedCharOrEof", - "tags": [] + "tags": [ + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "Any value passed to a function in shall be representable as an unsigned char or be the value EOF" @@ -29,7 +31,9 @@ "precision": "very-high", "severity": "error", "short_name": "MemcpyMemmoveMemcmpArgNotPointersToCompatibleTypes", - "tags": [] + "tags": [ + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "The pointer arguments to the Standard Library functions memcpy, memmove and memcmp shall be pointers to qualified or unqualified versions of compatible types" diff --git a/rule_packages/c/Statements1.json b/rule_packages/c/Statements1.json index a8dc1b55ea..c932a8642d 100644 --- a/rule_packages/c/Statements1.json +++ b/rule_packages/c/Statements1.json @@ -15,7 +15,8 @@ "shared_implementation_short_name": "NestedLabelInSwitch", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -35,7 +36,8 @@ "short_name": "BreakShallTerminateSwitchClause", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -55,7 +57,8 @@ "short_name": "EverySwitchShallHaveDefaultLabel", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -73,7 +76,9 @@ "precision": "very-high", "severity": "recommendation", "short_name": "DefaultNotFirstOrLastOfSwitch", - "tags": [] + "tags": [ + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "A default label shall appear as either the first or the last switch label of a switch statement" diff --git a/rule_packages/c/Statements2.json b/rule_packages/c/Statements2.json index cb616429be..9cd71b69c9 100644 --- a/rule_packages/c/Statements2.json +++ b/rule_packages/c/Statements2.json @@ -15,7 +15,8 @@ "shared_implementation_short_name": "GotoStatementCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -36,7 +37,8 @@ "shared_implementation_short_name": "GotoReferenceALabelInSurroundingBlock", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -56,7 +58,8 @@ "short_name": "LoopIterationCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -76,7 +79,8 @@ "short_name": "SwitchClauseNumberCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -96,7 +100,8 @@ "short_name": "SwitchExpressionBoolCondition", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Statements3.json b/rule_packages/c/Statements3.json index 5471749a49..94206d485f 100644 --- a/rule_packages/c/Statements3.json +++ b/rule_packages/c/Statements3.json @@ -14,7 +14,8 @@ "short_name": "SwitchCompoundCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -26,7 +27,8 @@ "short_name": "LoopCompoundCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -38,7 +40,8 @@ "short_name": "SelectionCompoundCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -59,7 +62,8 @@ "short_name": "IfElseEndCondition", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -80,7 +84,8 @@ "short_name": "SwitchCaseStartCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -93,7 +98,8 @@ "short_name": "SwitchStmtNotWellFormed", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -113,7 +119,8 @@ "short_name": "RecursiveFunctionCondition", "tags": [ "maintainability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Statements4.json b/rule_packages/c/Statements4.json index 56e13c9de6..5b0cc9be26 100644 --- a/rule_packages/c/Statements4.json +++ b/rule_packages/c/Statements4.json @@ -37,7 +37,8 @@ "short_name": "ForLoopNotWellFormed", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -57,7 +58,8 @@ "short_name": "NonBooleanIfCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] }, { @@ -69,7 +71,8 @@ "short_name": "NonBooleanIterationCondition", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Statements5.json b/rule_packages/c/Statements5.json index 93a533939b..329819b61f 100644 --- a/rule_packages/c/Statements5.json +++ b/rule_packages/c/Statements5.json @@ -15,7 +15,8 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -36,7 +37,8 @@ "tags": [ "maintainability", "readability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -58,11 +60,12 @@ "tags": [ "correctness", "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], "title": "All exit paths from a function with non-void return type shall have an explicit return statement with an expression" } } -} +} \ No newline at end of file diff --git a/rule_packages/c/Statements6.json b/rule_packages/c/Statements6.json index 8d71f11cfd..c8ab3efe38 100644 --- a/rule_packages/c/Statements6.json +++ b/rule_packages/c/Statements6.json @@ -15,7 +15,8 @@ "shared_implementation_short_name": "GotoStatementShouldNotBeUsed", "tags": [ "correctness", - "security" + "security", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Static.json b/rule_packages/c/Static.json index 7edf903703..2af2af402a 100644 --- a/rule_packages/c/Static.json +++ b/rule_packages/c/Static.json @@ -13,7 +13,8 @@ "severity": "error", "short_name": "UseOfArrayStatic", "tags": [ - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "The static keyword is associated with particular array types in our model. This means we can get false positives when two parameter use the same array type and size, but only one of which uses the `static` keyword." diff --git a/rule_packages/c/Syntax.json b/rule_packages/c/Syntax.json index 99bcf8250e..e588c366c0 100644 --- a/rule_packages/c/Syntax.json +++ b/rule_packages/c/Syntax.json @@ -14,7 +14,8 @@ "short_name": "CharacterSequencesAndUsedWithinAComment", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -35,7 +36,8 @@ "tags": [ "maintainability", "readability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -57,7 +59,8 @@ "tags": [ "maintainability", "readability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -79,7 +82,8 @@ "tags": [ "maintainability", "readability", - "correctness" + "correctness", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -100,7 +104,8 @@ "shared_implementation_short_name": "DifferentIdentifiersNotTypographicallyUnambiguous", "tags": [ "readability", - "maintainability" + "maintainability", + "external/misra/c/2012/third-edition-first-revision" ] } ], @@ -120,7 +125,8 @@ "short_name": "UOrUSuffixRepresentedInUnsignedType", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ], "implementation_scope": { "description": "This implementation does not consider constants defined in macro bodies." @@ -144,7 +150,8 @@ "shared_implementation_short_name": "LowercaseLStartsInLiteralSuffix", "tags": [ "maintainability", - "readability" + "readability", + "external/misra/c/2012/third-edition-first-revision" ] } ], diff --git a/rule_packages/c/Types1.json b/rule_packages/c/Types1.json index fae0339d3c..cbf7f0b632 100644 --- a/rule_packages/c/Types1.json +++ b/rule_packages/c/Types1.json @@ -48,7 +48,9 @@ "precision": "high", "severity": "error", "short_name": "PlainNumericalTypeUsedOverExplicitTypedef", - "tags": [] + "tags": [ + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "typedefs that indicate size and signedness should be used in place of the basic numerical types" @@ -65,7 +67,9 @@ "precision": "very-high", "severity": "error", "short_name": "SizeofOperatorUsedOnArrayTypeParam", - "tags": [] + "tags": [ + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "The sizeof operator shall not have an operand which is a function parameter declared as 'array of type'" @@ -82,10 +86,12 @@ "precision": "very-high", "severity": "error", "short_name": "StringLiteralAssignedToNonConstChar", - "tags": [] + "tags": [ + "external/misra/c/2012/third-edition-first-revision" + ] } ], "title": "A string literal shall not be assigned to an object unless the object's type is 'pointer to const-qualified char'" } } -} +} \ No newline at end of file From 4c9e0489befb910a7a7fbf24791286d771f90c0d Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Wed, 2 Oct 2024 22:40:10 +0100 Subject: [PATCH 26/62] MISRA C: Update query suites * Provide a query suite for MISRA C 2012, 3rd Edition with Amendment 2 * Provide query suites for required/advisory --- .../misra-c-2012-third-edition-with-amendment-2.qls | 13 +++++++++++++ c/misra/src/codeql-suites/misra-c-advisory.qls | 12 ++++++++++++ .../{misra-default.qls => misra-c-default.qls} | 0 c/misra/src/codeql-suites/misra-c-required.qls | 12 ++++++++++++ c/misra/src/qlpack.yml | 1 + 5 files changed, 38 insertions(+) create mode 100644 c/misra/src/codeql-suites/misra-c-2012-third-edition-with-amendment-2.qls create mode 100644 c/misra/src/codeql-suites/misra-c-advisory.qls rename c/misra/src/codeql-suites/{misra-default.qls => misra-c-default.qls} (100%) create mode 100644 c/misra/src/codeql-suites/misra-c-required.qls diff --git a/c/misra/src/codeql-suites/misra-c-2012-third-edition-with-amendment-2.qls b/c/misra/src/codeql-suites/misra-c-2012-third-edition-with-amendment-2.qls new file mode 100644 index 0000000000..8d06e7c2c8 --- /dev/null +++ b/c/misra/src/codeql-suites/misra-c-2012-third-edition-with-amendment-2.qls @@ -0,0 +1,13 @@ +- description: MISRA C 2012 - Third Edition, First Revision including Amendment 2 +- qlpack: codeql/misra-c-coding-standards +- include: + kind: + - problem + - path-problem + tags contain: + - external/misra/c/2012/third-edition-first-revision + - external/misra/c/2012/amendment2 +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled diff --git a/c/misra/src/codeql-suites/misra-c-advisory.qls b/c/misra/src/codeql-suites/misra-c-advisory.qls new file mode 100644 index 0000000000..517f449b13 --- /dev/null +++ b/c/misra/src/codeql-suites/misra-c-advisory.qls @@ -0,0 +1,12 @@ +- description: MISRA C 2012 (Advisory) +- qlpack: codeql/misra-c-coding-standards +- include: + kind: + - problem + - path-problem + tags contain: + - external/misra/obligation/advisory +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled diff --git a/c/misra/src/codeql-suites/misra-default.qls b/c/misra/src/codeql-suites/misra-c-default.qls similarity index 100% rename from c/misra/src/codeql-suites/misra-default.qls rename to c/misra/src/codeql-suites/misra-c-default.qls diff --git a/c/misra/src/codeql-suites/misra-c-required.qls b/c/misra/src/codeql-suites/misra-c-required.qls new file mode 100644 index 0000000000..ca32b9ca97 --- /dev/null +++ b/c/misra/src/codeql-suites/misra-c-required.qls @@ -0,0 +1,12 @@ +- description: MISRA C 2012 (Required) +- qlpack: codeql/misra-c-coding-standards +- include: + kind: + - problem + - path-problem + tags contain: + - external/misra/obligation/required +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled diff --git a/c/misra/src/qlpack.yml b/c/misra/src/qlpack.yml index fe7a2a0567..5de8472821 100644 --- a/c/misra/src/qlpack.yml +++ b/c/misra/src/qlpack.yml @@ -3,6 +3,7 @@ version: 2.36.0-dev description: MISRA C 2012 suites: codeql-suites license: MIT +default-suite-file: codeql-suites/misra-c-default.qls dependencies: codeql/common-c-coding-standards: '*' codeql/cpp-all: 0.9.3 From b2e35a77ce69059fbd89f69d7b4e52d30f954c83 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 09:17:00 +0100 Subject: [PATCH 27/62] Add change note for MISRA C query suite --- change_notes/2024-10-03-misra-c-query-suites.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 change_notes/2024-10-03-misra-c-query-suites.md diff --git a/change_notes/2024-10-03-misra-c-query-suites.md b/change_notes/2024-10-03-misra-c-query-suites.md new file mode 100644 index 0000000000..3eb3521ec9 --- /dev/null +++ b/change_notes/2024-10-03-misra-c-query-suites.md @@ -0,0 +1,6 @@ + - The following query suites have been added or modified for MISRA C: + - A new query suite has been created `misra-c-default.qls` to avoid confusion with the MISRA C++ query suites. The `misra-default.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-c-default.qls` suite. + - The `misra-c-default.qls` suite has been specified as the default for the pack, and will include our most up-to-date coverage for MISRA C. + - A new query suite `misra-c-2012-third-edition-with-amendment-2.qls` has been created to represent our previous MISRA C coverage. Note: this query suite will run the rules that were present in MISRA C 2012, Third Edition, First Revision and Amendment 2. The interpretation of those + rules may be updated to reflect changes in more recent MISRA standards. + - A pair of new query suites, `misra-c-required.qls` and `misra-c-advisory.qls`, have been added to enable running only the required or advisory queries. \ No newline at end of file From eb6e77c9192ced49a4acbd101526c9a88c4cd0fd Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 09:18:36 +0100 Subject: [PATCH 28/62] Re-add MISRA default suite for C To avoid compatibility problems --- c/misra/src/codeql-suites/misra-default.qls | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 c/misra/src/codeql-suites/misra-default.qls diff --git a/c/misra/src/codeql-suites/misra-default.qls b/c/misra/src/codeql-suites/misra-default.qls new file mode 100644 index 0000000000..343379a2b3 --- /dev/null +++ b/c/misra/src/codeql-suites/misra-default.qls @@ -0,0 +1,10 @@ +- description: MISRA C 2012 (Default) +- qlpack: codeql/misra-c-coding-standards +- include: + kind: + - problem + - path-problem +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled From d86432913437ffd75b040899b742c113c027fb49 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Wed, 2 Oct 2024 22:42:36 +0100 Subject: [PATCH 29/62] Update under development section --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d1de9b6372..cc148fbde3 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,10 @@ The following coding standards are supported: ## :construction: Standards under development :construction: -- [MISRA C++ 2023](https://misra.org.uk/product/misra-cpp2023/) - under development _scheduled for release 2024 Q4_. +The following standards are under active development: + +- [MISRA C++ 2023](https://misra.org.uk/product/misra-cpp2023/) - under development - _scheduled for release 2025 Q1_ +- [MISRA C 2023](https://misra.org.uk/product/misra-c2023/) - under development - _scheduled for release 2025 Q1_ ## How do I use the CodeQL Coding Standards Queries? From aed2b139770c2c7fa46eb5f0c96231394b375ec9 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 09:14:53 +0100 Subject: [PATCH 30/62] Update user manual and README for MISRA C 2023. --- README.md | 1 + docs/user_manual.md | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc148fbde3..0f24587afe 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ The following standards are under active development: - [MISRA C++ 2023](https://misra.org.uk/product/misra-cpp2023/) - under development - _scheduled for release 2025 Q1_ - [MISRA C 2023](https://misra.org.uk/product/misra-c2023/) - under development - _scheduled for release 2025 Q1_ + - This includes the development of [MISRA C 2012 Amendment 3](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD3.pdf) and [MISRA C 2012 Amendment 4](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD4.pdf), which are incorporated into MISRA C 2023. ## How do I use the CodeQL Coding Standards Queries? diff --git a/docs/user_manual.md b/docs/user_manual.md index 0d42e698fb..5799d73e6f 100644 --- a/docs/user_manual.md +++ b/docs/user_manual.md @@ -27,6 +27,7 @@ | 0.19.0 | 2024-02-23 | Remco Vermeulen | Clarify the required use of Python version 3.9. | | 0.20.0 | 2024-02-23 | Remco Vermeulen | Add table describing the permitted guideline re-categorizations. | | 0.21.0 | 2024-05-01 | Luke Cartey | Add MISRA C++ 2023 as under development, and clarify MISRA C 2012 coverage. | +| 0.22.0 | 2024-10-02 | Luke Cartey | Add MISRA C 2023 as under development, and clarify MISRA C 2012 coverage. ## Release information @@ -58,8 +59,11 @@ The _CodeQL Coding Standards_ product is a set of CodeQL queries for identifying | AUTOSAR C++ | [^1] [R22-11](https://www.autosar.org/fileadmin/standards/R22-11/AP/AUTOSAR_RS_CPP14Guidelines.pdf), R21-11, R20-11, R19-11, R19-03 | 397 | 372 | 370[^2] | Implemented | | CERT-C++ | [2016](https://resources.sei.cmu.edu/downloads/secure-coding/assets/sei-cert-cpp-coding-standard-2016-v01.pdf) | 83 | 82 | 82 | Implemented | | CERT C | [2016](https://resources.sei.cmu.edu/downloads/secure-coding/assets/sei-cert-c-coding-standard-2016-v01.pdf) | 99 | 97 | 97 | Implemented | -| MISRA C | [2012 Third Edition, First Revision](](https://www.misra.org.uk/product/misra-c2012-third-edition-first-revision/)), and [Amendment 2](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD2.pdf) and TC2 | 175 | 164 | 162[^3] | Implemented | -| MISRA C++ | [2023](https://misra.org.uk/product/misra-cpp2023/) | 179 | 176[^4] | 0 | Under development | +| MISRA C | [2012 Third Edition, First Revision](https://www.misra.org.uk/product/misra-c2012-third-edition-first-revision/), [Amendment 2](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD2.pdf) and TC2 | 175 | 164 | 162[^3] | Implemented | +| | [MISRA C 2012 Amendment 3](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD3.pdf) | 24 | 24 | - | Under development | +| | [MISRA C 2012 Amendment 4](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD4.pdf) | 22 | 22 | - | Under development | +| | [2023 Third Edition, Second Revision](https://misra.org.uk/product/misra-c2023/) | 221 | 210 | - | Under development | +| MISRA C++ | [2023](https://misra.org.uk/product/misra-cpp2023/) | 179 | 176[^4] | - | Under development | Not all rules in these standards are amenable to static analysis by CodeQL - some rules require external or domain specific knowledge to validate, or refer to properties which are not present in our representation of the codebase under analysis. In addition, some rules are natively enforced by the supported compilers. As CodeQL requires that the program under analysis compiles, we are unable to implement queries for these rules, and doing so would be redundant. From ecb3a4a6ddeae46ff9bb3852688d97672fc5ea5d Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 09:59:48 +0100 Subject: [PATCH 31/62] Add new MISRA C++ query suites Provide clearer naming for the MISRA C++ query suites, to avoid confusion with the MISRA C query suites. --- change_notes/2024-10-03-misra-c-query-suites.md | 6 +++++- cpp/misra/src/codeql-suites/misra-cpp-default.qls | 10 ++++++++++ .../misra-cpp-single-translation-unit.qls | 12 ++++++++++++ cpp/misra/src/codeql-suites/misra-default.qls | 12 ++---------- .../misra-single-translation-unit.qls | 14 ++------------ cpp/misra/src/qlpack.yml | 2 +- 6 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 cpp/misra/src/codeql-suites/misra-cpp-default.qls create mode 100644 cpp/misra/src/codeql-suites/misra-cpp-single-translation-unit.qls diff --git a/change_notes/2024-10-03-misra-c-query-suites.md b/change_notes/2024-10-03-misra-c-query-suites.md index 3eb3521ec9..067944cf2f 100644 --- a/change_notes/2024-10-03-misra-c-query-suites.md +++ b/change_notes/2024-10-03-misra-c-query-suites.md @@ -3,4 +3,8 @@ - The `misra-c-default.qls` suite has been specified as the default for the pack, and will include our most up-to-date coverage for MISRA C. - A new query suite `misra-c-2012-third-edition-with-amendment-2.qls` has been created to represent our previous MISRA C coverage. Note: this query suite will run the rules that were present in MISRA C 2012, Third Edition, First Revision and Amendment 2. The interpretation of those rules may be updated to reflect changes in more recent MISRA standards. - - A pair of new query suites, `misra-c-required.qls` and `misra-c-advisory.qls`, have been added to enable running only the required or advisory queries. \ No newline at end of file + - A pair of new query suites, `misra-c-required.qls` and `misra-c-advisory.qls`, have been added to enable running only the required or advisory queries. + - The following query suites have been added or modified for MISRA C++: + - A new query suite has been created `misra-cpp-default.qls` to avoid confusion with the MISRA C query suites. The `misra-default.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-cpp-default.qls` suite. + - The `misra-cpp-default.qls` suite has been specified as the default for the pack, and will include our most up-to-date coverage for MISRA C. + - A new query suite has been created `misra-cpp-single-translation-unit.qls` to avoid confusion with the MISRA C query suites. The `misra-single-translation-unit.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-cpp-single-translation-unit.qls` suite. \ No newline at end of file diff --git a/cpp/misra/src/codeql-suites/misra-cpp-default.qls b/cpp/misra/src/codeql-suites/misra-cpp-default.qls new file mode 100644 index 0000000000..670b043caa --- /dev/null +++ b/cpp/misra/src/codeql-suites/misra-cpp-default.qls @@ -0,0 +1,10 @@ +- description: MISRA C++ 2023 (Default) +- qlpack: codeql/misra-cpp-coding-standards +- include: + kind: + - problem + - path-problem +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled diff --git a/cpp/misra/src/codeql-suites/misra-cpp-single-translation-unit.qls b/cpp/misra/src/codeql-suites/misra-cpp-single-translation-unit.qls new file mode 100644 index 0000000000..0782dd876d --- /dev/null +++ b/cpp/misra/src/codeql-suites/misra-cpp-single-translation-unit.qls @@ -0,0 +1,12 @@ +- description: MISRA C++ 2023 (Single Translation Unit) +- qlpack: codeql/misra-cpp-coding-standards +- include: + kind: + - problem + - path-problem + tags contain: + - scope/single-translation-unit +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled diff --git a/cpp/misra/src/codeql-suites/misra-default.qls b/cpp/misra/src/codeql-suites/misra-default.qls index 670b043caa..8609e3df64 100644 --- a/cpp/misra/src/codeql-suites/misra-default.qls +++ b/cpp/misra/src/codeql-suites/misra-default.qls @@ -1,10 +1,2 @@ -- description: MISRA C++ 2023 (Default) -- qlpack: codeql/misra-cpp-coding-standards -- include: - kind: - - problem - - path-problem -- exclude: - tags contain: - - external/misra/audit - - external/misra/default-disabled +- description: "DEPRECATED - MISRA C++ 2023 - use misra-cpp-default.qls instead" +- import: codeql-suites/misra-cpp-default.qls \ No newline at end of file diff --git a/cpp/misra/src/codeql-suites/misra-single-translation-unit.qls b/cpp/misra/src/codeql-suites/misra-single-translation-unit.qls index 0782dd876d..0351768470 100644 --- a/cpp/misra/src/codeql-suites/misra-single-translation-unit.qls +++ b/cpp/misra/src/codeql-suites/misra-single-translation-unit.qls @@ -1,12 +1,2 @@ -- description: MISRA C++ 2023 (Single Translation Unit) -- qlpack: codeql/misra-cpp-coding-standards -- include: - kind: - - problem - - path-problem - tags contain: - - scope/single-translation-unit -- exclude: - tags contain: - - external/misra/audit - - external/misra/default-disabled +- description: "DEPRECATED - MISRA C++ 2023 (Single Translation Unit) - use misra-cpp-single-translation-unit.qls instead" +- import: codeql-suites/misra-cpp-single-translation-unit.qls \ No newline at end of file diff --git a/cpp/misra/src/qlpack.yml b/cpp/misra/src/qlpack.yml index 5e50eb563a..4c0aa45f4f 100644 --- a/cpp/misra/src/qlpack.yml +++ b/cpp/misra/src/qlpack.yml @@ -1,7 +1,7 @@ name: codeql/misra-cpp-coding-standards version: 2.36.0-dev description: MISRA C++ 2023 -suites: codeql-suites +default-suite: codeql-suites/misra-cpp-default.qls license: MIT dependencies: codeql/common-cpp-coding-standards: '*' From b60dcd07b5ef8355c2e58a94394fecd67031bcf6 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 10:08:28 +0100 Subject: [PATCH 32/62] Add query suites for mandatory, required and advisory rules. --- change_notes/2024-10-03-misra-c-query-suites.md | 3 ++- cpp/misra/src/codeql-suites/misra-cpp-advisory.qls | 12 ++++++++++++ cpp/misra/src/codeql-suites/misra-cpp-mandatory.qls | 12 ++++++++++++ cpp/misra/src/codeql-suites/misra-cpp-required.qls | 12 ++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 cpp/misra/src/codeql-suites/misra-cpp-advisory.qls create mode 100644 cpp/misra/src/codeql-suites/misra-cpp-mandatory.qls create mode 100644 cpp/misra/src/codeql-suites/misra-cpp-required.qls diff --git a/change_notes/2024-10-03-misra-c-query-suites.md b/change_notes/2024-10-03-misra-c-query-suites.md index 067944cf2f..2b34df98e5 100644 --- a/change_notes/2024-10-03-misra-c-query-suites.md +++ b/change_notes/2024-10-03-misra-c-query-suites.md @@ -7,4 +7,5 @@ - The following query suites have been added or modified for MISRA C++: - A new query suite has been created `misra-cpp-default.qls` to avoid confusion with the MISRA C query suites. The `misra-default.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-cpp-default.qls` suite. - The `misra-cpp-default.qls` suite has been specified as the default for the pack, and will include our most up-to-date coverage for MISRA C. - - A new query suite has been created `misra-cpp-single-translation-unit.qls` to avoid confusion with the MISRA C query suites. The `misra-single-translation-unit.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-cpp-single-translation-unit.qls` suite. \ No newline at end of file + - A new query suite has been created `misra-cpp-single-translation-unit.qls` to avoid confusion with the MISRA C query suites. The `misra-single-translation-unit.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-cpp-single-translation-unit.qls` suite. + - Three new query suites, `misra-cpp-mandatory.qls`, `misra-c-required.qls` and `misra-c-advisory.qls`, have been added to enable running mandatory, required or advisory queries. \ No newline at end of file diff --git a/cpp/misra/src/codeql-suites/misra-cpp-advisory.qls b/cpp/misra/src/codeql-suites/misra-cpp-advisory.qls new file mode 100644 index 0000000000..5da16cc2af --- /dev/null +++ b/cpp/misra/src/codeql-suites/misra-cpp-advisory.qls @@ -0,0 +1,12 @@ +- description: MISRA C++ 2023 (Default) +- qlpack: codeql/misra-cpp-coding-standards +- include: + kind: + - problem + - path-problem + tags contain: + - external/misra/obligation/advisory +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled diff --git a/cpp/misra/src/codeql-suites/misra-cpp-mandatory.qls b/cpp/misra/src/codeql-suites/misra-cpp-mandatory.qls new file mode 100644 index 0000000000..0c5ec7155f --- /dev/null +++ b/cpp/misra/src/codeql-suites/misra-cpp-mandatory.qls @@ -0,0 +1,12 @@ +- description: MISRA C++ 2023 (Default) +- qlpack: codeql/misra-cpp-coding-standards +- include: + kind: + - problem + - path-problem + tags contain: + - external/misra/obligation/mandatory +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled diff --git a/cpp/misra/src/codeql-suites/misra-cpp-required.qls b/cpp/misra/src/codeql-suites/misra-cpp-required.qls new file mode 100644 index 0000000000..2fe61301e7 --- /dev/null +++ b/cpp/misra/src/codeql-suites/misra-cpp-required.qls @@ -0,0 +1,12 @@ +- description: MISRA C++ 2023 (Default) +- qlpack: codeql/misra-cpp-coding-standards +- include: + kind: + - problem + - path-problem + tags contain: + - external/misra/obligation/required +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled From b06feabb069929e346dd18fa731826936bd286e3 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 10:10:49 +0100 Subject: [PATCH 33/62] Add MISRA C mandatory query suite --- c/misra/src/codeql-suites/misra-c-mandatory.qls | 12 ++++++++++++ change_notes/2024-10-03-misra-c-query-suites.md | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 c/misra/src/codeql-suites/misra-c-mandatory.qls diff --git a/c/misra/src/codeql-suites/misra-c-mandatory.qls b/c/misra/src/codeql-suites/misra-c-mandatory.qls new file mode 100644 index 0000000000..454b8487ab --- /dev/null +++ b/c/misra/src/codeql-suites/misra-c-mandatory.qls @@ -0,0 +1,12 @@ +- description: MISRA C 2012 (Advisory) +- qlpack: codeql/misra-c-coding-standards +- include: + kind: + - problem + - path-problem + tags contain: + - external/misra/obligation/mandatory +- exclude: + tags contain: + - external/misra/audit + - external/misra/default-disabled diff --git a/change_notes/2024-10-03-misra-c-query-suites.md b/change_notes/2024-10-03-misra-c-query-suites.md index 2b34df98e5..cdc6982673 100644 --- a/change_notes/2024-10-03-misra-c-query-suites.md +++ b/change_notes/2024-10-03-misra-c-query-suites.md @@ -3,7 +3,7 @@ - The `misra-c-default.qls` suite has been specified as the default for the pack, and will include our most up-to-date coverage for MISRA C. - A new query suite `misra-c-2012-third-edition-with-amendment-2.qls` has been created to represent our previous MISRA C coverage. Note: this query suite will run the rules that were present in MISRA C 2012, Third Edition, First Revision and Amendment 2. The interpretation of those rules may be updated to reflect changes in more recent MISRA standards. - - A pair of new query suites, `misra-c-required.qls` and `misra-c-advisory.qls`, have been added to enable running only the required or advisory queries. + - Three new query suites, `misra-c-mandatory.qls`, `misra-c-required.qls` and `misra-c-advisory.qls`, have been added to enable running mandatory, required or advisory queries. - The following query suites have been added or modified for MISRA C++: - A new query suite has been created `misra-cpp-default.qls` to avoid confusion with the MISRA C query suites. The `misra-default.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-cpp-default.qls` suite. - The `misra-cpp-default.qls` suite has been specified as the default for the pack, and will include our most up-to-date coverage for MISRA C. From fee630ba3ccdeea6f92e87d115a89b459244c67f Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 10:11:49 +0100 Subject: [PATCH 34/62] MISRA C misra-default.qls update deprecation message, use import --- c/misra/src/codeql-suites/misra-default.qls | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/c/misra/src/codeql-suites/misra-default.qls b/c/misra/src/codeql-suites/misra-default.qls index 343379a2b3..66a0161628 100644 --- a/c/misra/src/codeql-suites/misra-default.qls +++ b/c/misra/src/codeql-suites/misra-default.qls @@ -1,10 +1,2 @@ -- description: MISRA C 2012 (Default) -- qlpack: codeql/misra-c-coding-standards -- include: - kind: - - problem - - path-problem -- exclude: - tags contain: - - external/misra/audit - - external/misra/default-disabled +- description: "DEPRECATED - MISRA C 2012 - use misra-c-default.qls instead" +- import: codeql-suites/misra-c-default.qls \ No newline at end of file From c407583245e547afc2ead0590f698f78d3accafe Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 10:34:52 +0100 Subject: [PATCH 35/62] Update schema validation with new tags --- schemas/rule-package.schema.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/schemas/rule-package.schema.json b/schemas/rule-package.schema.json index daeb1ade51..b27815163e 100644 --- a/schemas/rule-package.schema.json +++ b/schemas/rule-package.schema.json @@ -338,7 +338,11 @@ "external/cert/default-disabled", "external/autosar/strict", "scope/single-translation-unit", - "scope/system" + "scope/system", + "external/misra/c/2012/third-edition-first-revision", + "external/misra/c/2012/amendment2", + "external/misra/c/2012/amendment3", + "external/misra/c/2012/amendment4" ] }, "minLength": 1 From 8cfa9cfa49a18f50578ac4bfcca5f7125fa6509e Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 23:31:50 +0100 Subject: [PATCH 36/62] Upgrade CodeQL dependencies now updates qlpack.yml files The appropriate version of the `codeql/cpp-all` pack is identified by querying the qlpack.yml of the tag for the CodeQL version on github/codeql. This is then applied to all relevant qlpack.yml files in the repo, then codeql pack upgrade is used to update the lock files. --- .../requirements.txt | 1 + .../upgrade-codeql-dependencies.py | 47 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/scripts/upgrade-codeql-dependencies/requirements.txt b/scripts/upgrade-codeql-dependencies/requirements.txt index 009d2dc5aa..55b810e4aa 100644 --- a/scripts/upgrade-codeql-dependencies/requirements.txt +++ b/scripts/upgrade-codeql-dependencies/requirements.txt @@ -4,3 +4,4 @@ idna==3.4 requests==2.31.0 semantic-version==2.10.0 urllib3==1.26.18 +pyyaml==6.0.1 \ No newline at end of file diff --git a/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py b/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py index 6c98216ca0..6d0baab609 100644 --- a/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py +++ b/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py @@ -1,18 +1,23 @@ import json import requests -from typing import Optional, Dict, List +from typing import Optional, Dict, List, Tuple from semantic_version import Version from pathlib import Path +import yaml SCRIPT_PATH = Path(__file__) -SUPPORTED_VERSIONS_PATH = SCRIPT_PATH.parent.parent.parent / "supported_codeql_configs.json" +CODING_STANDARDS_ROOT = SCRIPT_PATH.parent.parent.parent +SUPPORTED_VERSIONS_PATH = CODING_STANDARDS_ROOT / "supported_codeql_configs.json" -def get_compatible_stdlib(version: Version) -> Optional[str]: +def get_compatible_stdlib(version: Version) -> Optional[Tuple[str, str]]: tag = f"codeql-cli/v{version}" response = requests.get(f"https://raw.githubusercontent.com/github/codeql/{tag}/cpp/ql/lib/qlpack.yml") if response.status_code == 200: - return tag + # Parse the qlpack.yml returned in the response as a yaml file to read the version property + qlpack = yaml.safe_load(response.text) + if qlpack is not None and "version" in qlpack: + return (tag, qlpack["version"]) return None def get_compatible_bundle(version: Version, token: str) -> Optional[str]: @@ -30,8 +35,8 @@ def get_compatible_bundle(version: Version, token: str) -> Optional[str]: def main(cli_version : str, github_token: str) -> None: try: parsed_cli_version = Version(cli_version) - compatible_stdlib = get_compatible_stdlib(parsed_cli_version) - if compatible_stdlib is None: + compatible_stdlib_return = get_compatible_stdlib(parsed_cli_version) + if compatible_stdlib_return is None: print(f"Unable to find compatible standard library for: {parsed_cli_version}") exit(1) compatible_bundle = get_compatible_bundle(parsed_cli_version, github_token) @@ -39,6 +44,8 @@ def main(cli_version : str, github_token: str) -> None: print(f"Unable to find compatible bundle for: {parsed_cli_version}") exit(1) + compatible_stdlib_tag, compatible_stdlib_version = compatible_stdlib_return + with SUPPORTED_VERSIONS_PATH.open("r") as f: supported_versions = json.load(f) @@ -49,10 +56,36 @@ def main(cli_version : str, github_token: str) -> None: supported_env = supported_envs[0] supported_env["codeql_cli"] = str(parsed_cli_version) supported_env["codeql_cli_bundle"] = compatible_bundle - supported_env["codeql_standard_library"] = compatible_stdlib + supported_env["codeql_standard_library"] = compatible_stdlib_tag with SUPPORTED_VERSIONS_PATH.open("w") as f: json.dump(supported_versions, f, indent=2) + + # Find every qlpack.yml file in the repository + qlpack_files = list(CODING_STANDARDS_ROOT.rglob("qlpack.yml")) + # Filter out any files that are in a hidden directory + qlpack_files = [f for f in qlpack_files if not any(part for part in f.parts if part.startswith("."))] + + # Update the "codeql/cpp-all" entries in the "dependencies" property in every qlpack.yml file + updated_qlpacks = [] + for qlpack_file in qlpack_files: + with qlpack_file.open("r") as f: + qlpack = yaml.safe_load(f) + print("Updating dependencies in " + str(qlpack_file)) + if "codeql/cpp-all" in qlpack["dependencies"]: + qlpack["dependencies"]["codeql/cpp-all"] = compatible_stdlib_version + with qlpack_file.open("w") as f: + yaml.safe_dump(qlpack, f) + updated_qlpacks.append(qlpack_file.parent) + + # Call CodeQL to update the lock files by running codeql pack upgrade + # Note: we need to do this after updating all the qlpack files, + # otherwise we may get dependency resolution errors + for qlpack in updated_qlpacks: + print("Updating lock files for " + str(qlpack)) + os.system(f"codeql pack upgrade {qlpack}") + + except ValueError as e: print(e) exit(1) From 4b13ea4fab6093653d72156b2842731cdf2ebcd1 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 23:41:46 +0100 Subject: [PATCH 37/62] Upgrade workflow now provides codeql binary on path This enables the python script to update the lock files --- .../workflows/upgrade_codeql_dependencies.yml | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/upgrade_codeql_dependencies.yml b/.github/workflows/upgrade_codeql_dependencies.yml index 73721d5581..34018f9da8 100644 --- a/.github/workflows/upgrade_codeql_dependencies.yml +++ b/.github/workflows/upgrade_codeql_dependencies.yml @@ -20,6 +20,16 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - name: Fetch CodeQL + env: + GITHUB_TOKEN: ${{ github.token }} + RUNNER_TEMP: ${{ runner.temp }} + run: | + cd $RUNNER_TEMP + gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip + unzip -q codeql-linux64.zip + echo "$RUNNER_TEMP/codeql/" >> $GITHUB_PATH + - name: Install Python uses: actions/setup-python@v4 with: @@ -35,21 +45,12 @@ jobs: run: | python3 scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py --cli-version "$CODEQL_CLI_VERSION" - - name: Fetch CodeQL - env: - GITHUB_TOKEN: ${{ github.token }} - RUNNER_TEMP: ${{ runner.temp }} - run: | - cd $RUNNER_TEMP - gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip - unzip -q codeql-linux64.zip - - name: Update CodeQL formatting based on new CLI version env: RUNNER_TEMP: ${{ runner.temp }} run: | - find cpp \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" $RUNNER_TEMP/codeql/codeql query format --in-place - find c \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" $RUNNER_TEMP/codeql/codeql query format --in-place + find cpp \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place + find c \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place - name: Create Pull Request uses: peter-evans/create-pull-request@v3 From 1fe51d596cbf8e360cbf662dab0a40a663c109c6 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 23:42:24 +0100 Subject: [PATCH 38/62] Update upgrade documentation Improve the documentation and automatic commit message for upgrades. --- .github/workflows/upgrade_codeql_dependencies.yml | 13 +++++++++++-- docs/development_handbook.md | 14 +++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/upgrade_codeql_dependencies.yml b/.github/workflows/upgrade_codeql_dependencies.yml index 34018f9da8..a978980e11 100644 --- a/.github/workflows/upgrade_codeql_dependencies.yml +++ b/.github/workflows/upgrade_codeql_dependencies.yml @@ -55,8 +55,17 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v3 with: - title: "Upgrading `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}" - body: "This PR upgrades the CodeQL CLI version to ${{ github.event.inputs.codeql_cli_version }}." + title: "Upgrade `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}" + body: | + This PR upgrades the CodeQL CLI version to ${{ github.event.inputs.codeql_cli_version }}. + + ## CodeQL dependency upgrade checklist: + + - [ ] Confirm the code has been correctly reformatted according to the new CodeQL CLI. + - [ ] Identify any CodeQL compiler warnings and errors, and update queries as required. + - [ ] Validate that the `github/codeql` test cases succeed. + - [ ] Address any CodeQL test failures in the `github/codeql-coding-standards` repository. + - [ ] Validate performance vs pre-upgrade, using /test-performance commit-message: "Upgrading `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}" delete-branch: true branch: "codeql/upgrade-to-${{ github.event.inputs.codeql_cli_version }}" diff --git a/docs/development_handbook.md b/docs/development_handbook.md index de283bb946..b9f5bd9e74 100644 --- a/docs/development_handbook.md +++ b/docs/development_handbook.md @@ -514,23 +514,15 @@ To upgrade the CodeQL external dependencies: 5. Submit a Pull Request to the `github/codeql-coding-standards` repository with the title `Upgrade `github/codeql` dependency to `. Use this template for the description, filling : ```md - This PR updates the `supported_codeql_configs.json` file to target: - - - CodeQL CLI - - CodeQL Standard Library - - GHES - - CodeQL CLI Bundle - - > - + This PR updates the `supported_codeql_configs.json` file to target CodeQL CLI . ## CodeQL dependency upgrade checklist: - - [ ] Reformat our CodeQL using the latest version (if required) + - [ ] Confirm the code has been correctly reformatted according to the new CodeQL CLI. - [ ] Identify any CodeQL compiler warnings and errors, and update queries as required. - [ ] Validate that the `github/codeql` test cases succeed. - [ ] Address any CodeQL test failures in the `github/codeql-coding-standards` repository. - - [ ] Validate performance vs pre-upgrade + - [ ] Validate performance vs pre-upgrade, using /test-performance ``` 6. Follow the dependency upgrade checklist, confirming each step. The `.github/workflows/standard_library_upgrade_tests.yml` will trigger automation for running the `github/codeql` unit tests with the appropriate CLI version. From 8bd60fb7956882f3b27e7720ae63fff5d6e9e427 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 23:54:58 +0100 Subject: [PATCH 39/62] Developer handbook: improve upgrade documentation - Remove reference to GHES, which is no longer required. - Clarify use of the automatic workflow vs. manual workflow --- docs/development_handbook.md | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/development_handbook.md b/docs/development_handbook.md index b9f5bd9e74..dc50bf59ff 100644 --- a/docs/development_handbook.md +++ b/docs/development_handbook.md @@ -496,12 +496,11 @@ There are two external dependencies required for running the coding standards qu For the purpose of this repository, and any tool qualification, we consider these external dependencies to be "black boxes" which require verification when upgrading. -To (a) clearly specify the supported versions of these external dependencies and to (b) enable automation around them, the repository contains a `supported_codeql_configs.json` which lists the sets of supported configurations. There are four fields: +To (a) clearly specify the supported versions of these external dependencies and to (b) enable automation around them, the repository contains a `supported_codeql_configs.json` which lists the sets of supported configurations under the `supported_environments` property. There are three fields: - `codeql_cli` - this is the plain version number of the supported CodeQL CLI, e.g. `2.6.3`. - `codeql_standard_library` - this is the name of a tag on the `github.com/github/codeql` repository. The tag should be compatible with the CodeQL CLI given above. This would typically use the `codeql-cli/v` tag for the release, although any tag which is compatible is allowed. - `codeql_cli_bundle` - (optional) - if present, describes the CodeQL CLI bundle version that is compatible. The bundle should include precisely the CodeQL CLI version and CodeQL Standard Library versions specified in the two mandatory fields. -- `ghes` - (optional) - if present describes the GitHub Enterprise Server release whose integrated copy of the CodeQL Action points to the CodeQL CLI bundle specified in the `codeql_cli_bundle` field. #### Upgrading external dependencies @@ -509,9 +508,24 @@ To upgrade the CodeQL external dependencies: 1. Determine appropriate versions of the CodeQL CLI and `github/codeql` repository, according to the release schedule and customer demands. 2. Determine if there is a compatible CodeQL CLI bundle version by looking at the releases specified at [CodeQL Action releases](https://github.com/github/codeql-action/releases). The bundle always includes the standard library at the version specified by the `codeql-cli/v` tag in the `github/codeql` repository. -3. If you find a compatible CodeQL CLI bundle, determine whether that bundle was released in a GitHub Enterprise server release, by inspecting the `defaults.json` file at https://github.com/github/codeql-action/blob/main/lib/defaults.json#L2 for the CodeQL Action submitted with -4. Populated the `supported_codeql_configs.json` file with the given values, ensuring to delete the optional fields if they are not populated. -5. Submit a Pull Request to the `github/codeql-coding-standards` repository with the title `Upgrade `github/codeql` dependency to `. Use this template for the description, filling : + +If all components are being upgraded to a consistent veresion (e.g. CodeQL CLI v2.15.5, with `github/codeql` tag `codeql-cli/v2.15.5` and bundle `codeql-cli-bundle-v2.15.5`) then the following process can be used: + +1. Run the [upgrade_codeql_dependencies.yml](./github/workflows/upgrade_codeql_dependencies.yml) workflow, with the plain version number, e.g. `2.15.5`. This will: + - Download the specified version of the CodeQL CLI + - Run the [upgrade-codeql-dependencies.py](scripts/release/upgrade-codeql-dependencies.py) script, which + - Validates the version selected exists in all relevant places + - Updates the `supported_codeql_configs.json` file. + - Updates each `qlpack.yml` in the repository with an appropriate value for the `codeql/cpp-all` pack, consistent with the selected CodeQL CLI version. + - Updates each `codeql-lock.yml` file to upgrade to the new version. +2. Follow the dependency upgrade checklist, confirming each step. The `.github/workflows/standard_library_upgrade_tests.yml` will trigger automation for running the `github/codeql` unit tests with the appropriate CLI version. +3. Once all the automate tests have passed, and the checklist is complete, the PR can be merged. +4. An internal notification should be shared with the development team. + +If the upgrade is of mismatched versions you will need to manually create the upgrade following this process: + +1. Populate the `supported_codeql_configs.json` file with the given values, ensuring to delete the optional fields if they are not populated. +2. Submit a Pull Request to the `github/codeql-coding-standards` repository with the title `Upgrade `github/codeql` dependency to `. Use this template for the description, filling: ```md This PR updates the `supported_codeql_configs.json` file to target CodeQL CLI . @@ -525,9 +539,10 @@ To upgrade the CodeQL external dependencies: - [ ] Validate performance vs pre-upgrade, using /test-performance ``` -6. Follow the dependency upgrade checklist, confirming each step. The `.github/workflows/standard_library_upgrade_tests.yml` will trigger automation for running the `github/codeql` unit tests with the appropriate CLI version. -7. Once all the automate tests have passed, and the checklist is complete, the PR can be merged. -8. An internal notification should be shared with the development team. +3. Follow the dependency upgrade checklist, confirming each step. The `.github/workflows/standard_library_upgrade_tests.yml` will trigger automation for running the `github/codeql` unit tests with the appropriate CLI version. +4. Once all the automate tests have passed, and the checklist is complete, the PR can be merged. +5. An internal notification should be shared with the development team. + ### Release process From 6e89bb14c19a74284522fafd7f7280397a29b40e Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 3 Oct 2024 23:55:46 +0100 Subject: [PATCH 40/62] Upgrade CodeQL - ensure minimal changes to qlpacks.yml Ensure the qlpack.yml files are written out in the same order they were read. --- .../upgrade-codeql-dependencies/upgrade-codeql-dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py b/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py index 6d0baab609..ab947f0ef2 100644 --- a/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py +++ b/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py @@ -75,7 +75,7 @@ def main(cli_version : str, github_token: str) -> None: if "codeql/cpp-all" in qlpack["dependencies"]: qlpack["dependencies"]["codeql/cpp-all"] = compatible_stdlib_version with qlpack_file.open("w") as f: - yaml.safe_dump(qlpack, f) + yaml.safe_dump(qlpack, f, sort_keys=False) updated_qlpacks.append(qlpack_file.parent) # Call CodeQL to update the lock files by running codeql pack upgrade From 6278a0948974f2058c46456f475bcdf206a1761d Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 10:23:24 +0100 Subject: [PATCH 41/62] Upgrade GitHub Actions versions Upgrade to versions which use a more recent node. --- .github/workflows/upgrade_codeql_dependencies.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/upgrade_codeql_dependencies.yml b/.github/workflows/upgrade_codeql_dependencies.yml index a978980e11..b2be95a055 100644 --- a/.github/workflows/upgrade_codeql_dependencies.yml +++ b/.github/workflows/upgrade_codeql_dependencies.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Fetch CodeQL env: @@ -31,7 +31,7 @@ jobs: echo "$RUNNER_TEMP/codeql/" >> $GITHUB_PATH - name: Install Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.9" @@ -53,7 +53,7 @@ jobs: find c \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 + uses: peter-evans/create-pull-request@v7 with: title: "Upgrade `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}" body: | From 51e4d9534f0ccadc8d80ccfbd0b3ed329f3fd2b2 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 10:27:18 +0100 Subject: [PATCH 42/62] Use pinned commit to avoid supply chain injection --- .github/workflows/upgrade_codeql_dependencies.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upgrade_codeql_dependencies.yml b/.github/workflows/upgrade_codeql_dependencies.yml index b2be95a055..841b78fcd6 100644 --- a/.github/workflows/upgrade_codeql_dependencies.yml +++ b/.github/workflows/upgrade_codeql_dependencies.yml @@ -53,7 +53,7 @@ jobs: find c \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place - name: Create Pull Request - uses: peter-evans/create-pull-request@v7 + uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5 with: title: "Upgrade `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}" body: | From 6da5c4d051489348935a9e47ed980733e62931da Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 11:11:08 +0100 Subject: [PATCH 43/62] Address whitespace issues --- c/misra/src/codeql-suites/misra-default.qls | 2 +- change_notes/2024-10-03-misra-c-query-suites.md | 3 +-- cpp/misra/src/codeql-suites/misra-default.qls | 2 +- cpp/misra/src/codeql-suites/misra-single-translation-unit.qls | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/c/misra/src/codeql-suites/misra-default.qls b/c/misra/src/codeql-suites/misra-default.qls index 66a0161628..e645bb1545 100644 --- a/c/misra/src/codeql-suites/misra-default.qls +++ b/c/misra/src/codeql-suites/misra-default.qls @@ -1,2 +1,2 @@ - description: "DEPRECATED - MISRA C 2012 - use misra-c-default.qls instead" -- import: codeql-suites/misra-c-default.qls \ No newline at end of file +- import: codeql-suites/misra-c-default.qls diff --git a/change_notes/2024-10-03-misra-c-query-suites.md b/change_notes/2024-10-03-misra-c-query-suites.md index cdc6982673..c60aac8941 100644 --- a/change_notes/2024-10-03-misra-c-query-suites.md +++ b/change_notes/2024-10-03-misra-c-query-suites.md @@ -1,8 +1,7 @@ - The following query suites have been added or modified for MISRA C: - A new query suite has been created `misra-c-default.qls` to avoid confusion with the MISRA C++ query suites. The `misra-default.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-c-default.qls` suite. - The `misra-c-default.qls` suite has been specified as the default for the pack, and will include our most up-to-date coverage for MISRA C. - - A new query suite `misra-c-2012-third-edition-with-amendment-2.qls` has been created to represent our previous MISRA C coverage. Note: this query suite will run the rules that were present in MISRA C 2012, Third Edition, First Revision and Amendment 2. The interpretation of those - rules may be updated to reflect changes in more recent MISRA standards. + - A new query suite `misra-c-2012-third-edition-with-amendment-2.qls` has been created to represent our previous MISRA C coverage. Note: this query suite will run the rules that were present in MISRA C 2012, Third Edition, First Revision and Amendment 2. The interpretation of those rules may be updated to reflect changes in more recent MISRA standards. - Three new query suites, `misra-c-mandatory.qls`, `misra-c-required.qls` and `misra-c-advisory.qls`, have been added to enable running mandatory, required or advisory queries. - The following query suites have been added or modified for MISRA C++: - A new query suite has been created `misra-cpp-default.qls` to avoid confusion with the MISRA C query suites. The `misra-default.qls` suite has been deprecated, and will be removed in a future releases, and is replaced by the `misra-cpp-default.qls` suite. diff --git a/cpp/misra/src/codeql-suites/misra-default.qls b/cpp/misra/src/codeql-suites/misra-default.qls index 8609e3df64..3c205157cd 100644 --- a/cpp/misra/src/codeql-suites/misra-default.qls +++ b/cpp/misra/src/codeql-suites/misra-default.qls @@ -1,2 +1,2 @@ - description: "DEPRECATED - MISRA C++ 2023 - use misra-cpp-default.qls instead" -- import: codeql-suites/misra-cpp-default.qls \ No newline at end of file +- import: codeql-suites/misra-cpp-default.qls diff --git a/cpp/misra/src/codeql-suites/misra-single-translation-unit.qls b/cpp/misra/src/codeql-suites/misra-single-translation-unit.qls index 0351768470..9dcd3f0c97 100644 --- a/cpp/misra/src/codeql-suites/misra-single-translation-unit.qls +++ b/cpp/misra/src/codeql-suites/misra-single-translation-unit.qls @@ -1,2 +1,2 @@ - description: "DEPRECATED - MISRA C++ 2023 (Single Translation Unit) - use misra-cpp-single-translation-unit.qls instead" -- import: codeql-suites/misra-cpp-single-translation-unit.qls \ No newline at end of file +- import: codeql-suites/misra-cpp-single-translation-unit.qls From 5497cfafca5f671db2221dfa659e4719ebbc4b3e Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 11:41:23 +0100 Subject: [PATCH 44/62] Update NoReturn.json with MISRA C 2012 tags --- rule_packages/c/NoReturn.json | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rule_packages/c/NoReturn.json b/rule_packages/c/NoReturn.json index 49cdb4c255..f485060095 100644 --- a/rule_packages/c/NoReturn.json +++ b/rule_packages/c/NoReturn.json @@ -12,7 +12,10 @@ "precision": "very-high", "severity": "recommendation", "short_name": "NonVoidReturnTypeOfNoreturnFunction", - "tags": ["correctness"] + "tags": [ + "correctness", + "external/misra/c/2012/amendment3" + ] } ], "title": "A function declared with _noreturn shall have a return type of void" @@ -29,7 +32,10 @@ "precision": "very-high", "severity": "recommendation", "short_name": "FunctionWithNoReturningBranchShouldBeNoreturn", - "tags": ["correctness"] + "tags": [ + "correctness", + "external/misra/c/2012/amendment3" + ] } ], "title": "A function without a branch that returns shall be declared with _Noreturn" @@ -46,7 +52,10 @@ "precision": "very-high", "severity": "error", "short_name": "ReturnStatementInNoreturnFunction", - "tags": ["correctness"], + "tags": [ + "correctness", + "external/misra/c/2012/amendment3" + ], "shared_implementation_short_name": "FunctionNoReturnAttributeCondition" } ], From 4b9e9fdd18b905fd455dae9028fefcc512316eb8 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 11:41:40 +0100 Subject: [PATCH 45/62] Check MISRA C 2012 rules have MISRA C 2012 tags Needed to specify which amendment or rule set they come from. --- scripts/verify_rule_package_consistency.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/verify_rule_package_consistency.py b/scripts/verify_rule_package_consistency.py index 7d111e81bc..1f3ab337b4 100644 --- a/scripts/verify_rule_package_consistency.py +++ b/scripts/verify_rule_package_consistency.py @@ -100,6 +100,11 @@ print( f" - ERROR: Rule {rule_id} included in {package_name}.json but not marked as supportable in rules.csv.") failed = True + for query in rule_details["queries"]: + if standard_name == "MISRA-C-2012" and not any(tag for tag in query["tags"] if tag.startswith("external/misra/c/2012/")): + print( + f" - ERROR: MISRA C 2012 query {query["name"]} for Rule {rule_id} in {package_name}.json is missing a `external/misra/c/2012/...` tag.") + failed = True rules_csv_rule_ids = package_rules_from_csv[package_name] json_missing_rules = rules_csv_rule_ids.difference(package_json_rule_ids) From aab6e177af7431fd6c1c4ac5b882e5bc3a3196e2 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 11:41:40 +0100 Subject: [PATCH 46/62] Check MISRA C 2012 tags are not on other rules --- scripts/verify_rule_package_consistency.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/verify_rule_package_consistency.py b/scripts/verify_rule_package_consistency.py index 1f3ab337b4..57caee8bb8 100644 --- a/scripts/verify_rule_package_consistency.py +++ b/scripts/verify_rule_package_consistency.py @@ -103,7 +103,11 @@ for query in rule_details["queries"]: if standard_name == "MISRA-C-2012" and not any(tag for tag in query["tags"] if tag.startswith("external/misra/c/2012/")): print( - f" - ERROR: MISRA C 2012 query {query["name"]} for Rule {rule_id} in {package_name}.json is missing a `external/misra/c/2012/...` tag.") + f" - ERROR: MISRA C 2012 query {query["short_name"]}.ql for Rule {rule_id} in {package_name}.json is missing a `external/misra/c/2012/...` tag.") + failed = True + if not standard_name == "MISRA-C-2012" and any(tag for tag in query["tags"] if tag.startswith("external/misra/c/2012/")): + print( + f" - ERROR: {standard_name} query {query["short_name"]}.ql for Rule {rule_id} in {package_name}.json has a spurious `external/misra/c/2012/...` tag.") failed = True rules_csv_rule_ids = package_rules_from_csv[package_name] From 7cc5b574fa734ec48f8c998c4e0dfbe5562c0cfb Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 11:56:21 +0100 Subject: [PATCH 47/62] Upgrade all qlpacks Otherwise the lock files may not be updated for packs which transitively depend on codeql/cpp-all --- .../upgrade-codeql-dependencies.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py b/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py index ab947f0ef2..f6ab6aa383 100644 --- a/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py +++ b/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py @@ -67,7 +67,6 @@ def main(cli_version : str, github_token: str) -> None: qlpack_files = [f for f in qlpack_files if not any(part for part in f.parts if part.startswith("."))] # Update the "codeql/cpp-all" entries in the "dependencies" property in every qlpack.yml file - updated_qlpacks = [] for qlpack_file in qlpack_files: with qlpack_file.open("r") as f: qlpack = yaml.safe_load(f) @@ -76,12 +75,14 @@ def main(cli_version : str, github_token: str) -> None: qlpack["dependencies"]["codeql/cpp-all"] = compatible_stdlib_version with qlpack_file.open("w") as f: yaml.safe_dump(qlpack, f, sort_keys=False) - updated_qlpacks.append(qlpack_file.parent) # Call CodeQL to update the lock files by running codeql pack upgrade # Note: we need to do this after updating all the qlpack files, # otherwise we may get dependency resolution errors - for qlpack in updated_qlpacks: + # Note: we need to update all qlpack files, because they may + # transitively depend on the packs we changed + for qlpack_file in qlpack_files: + qlpack = qlpack.parent print("Updating lock files for " + str(qlpack)) os.system(f"codeql pack upgrade {qlpack}") From cbc63883d7b82c28b7166b7b106d3cfcc3c61563 Mon Sep 17 00:00:00 2001 From: Nicolas Will Date: Fri, 4 Oct 2024 13:29:03 +0200 Subject: [PATCH 48/62] Update c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected --- .../rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected index d0303f9a7f..0e2cbb26ee 100644 --- a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected +++ b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected @@ -23,7 +23,7 @@ | test.c:182:8:182:11 | gf19 | Empty structures are a compiler extension and are not portable to other compilers. | | test.c:216:9:216:10 | definition of x1 | Zero length arrays are a compiler extension and are not portable to other compilers. | | test.c:266:16:266:21 | access | Use of attribute 'access' is a compiler extension and is not portable to other compilers. | -| test.c:270:5:270:9 | alias | Use of attribute 'alias' is a compiler extension and is not portable to other compilers. | +| test.c:269:27:269:31 | alias | Use of attribute 'alias' is a compiler extension and is not portable to other compilers. | | test.c:272:23:272:29 | aligned | Use of attribute 'aligned' is a compiler extension and is not portable to other compilers. | | test.c:283:25:283:34 | deprecated | Use of attribute 'deprecated' is a compiler extension and is not portable to other compilers. | | test.c:295:20:295:30 | fallthrough | Use of attribute 'fallthrough' is a compiler extension and is not portable to other compilers. | From 61e7c6da6f98d0933477674b52c25828df2c2283 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 14:17:40 +0100 Subject: [PATCH 49/62] Fix typo --- .../upgrade-codeql-dependencies/upgrade-codeql-dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py b/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py index f6ab6aa383..c76303e654 100644 --- a/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py +++ b/scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py @@ -82,7 +82,7 @@ def main(cli_version : str, github_token: str) -> None: # Note: we need to update all qlpack files, because they may # transitively depend on the packs we changed for qlpack_file in qlpack_files: - qlpack = qlpack.parent + qlpack = qlpack_file.parent print("Updating lock files for " + str(qlpack)) os.system(f"codeql pack upgrade {qlpack}") From 0f89f16c2cd404ed21ec2c2b84ba7e93532a9b82 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 14:31:41 +0100 Subject: [PATCH 50/62] Avoid confusion over double quotes in double quotes --- scripts/verify_rule_package_consistency.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/verify_rule_package_consistency.py b/scripts/verify_rule_package_consistency.py index 57caee8bb8..034e367db2 100644 --- a/scripts/verify_rule_package_consistency.py +++ b/scripts/verify_rule_package_consistency.py @@ -103,11 +103,11 @@ for query in rule_details["queries"]: if standard_name == "MISRA-C-2012" and not any(tag for tag in query["tags"] if tag.startswith("external/misra/c/2012/")): print( - f" - ERROR: MISRA C 2012 query {query["short_name"]}.ql for Rule {rule_id} in {package_name}.json is missing a `external/misra/c/2012/...` tag.") + f' - ERROR: MISRA C 2012 query {query["short_name"]}.ql for Rule {rule_id} in {package_name}.json is missing a `external/misra/c/2012/...` tag.') failed = True if not standard_name == "MISRA-C-2012" and any(tag for tag in query["tags"] if tag.startswith("external/misra/c/2012/")): print( - f" - ERROR: {standard_name} query {query["short_name"]}.ql for Rule {rule_id} in {package_name}.json has a spurious `external/misra/c/2012/...` tag.") + f' - ERROR: {standard_name} query {query["short_name"]}.ql for Rule {rule_id} in {package_name}.json has a spurious `external/misra/c/2012/...` tag.') failed = True rules_csv_rule_ids = package_rules_from_csv[package_name] From 893231056dc2b91e753748825352284ffc9aa88e Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 14:53:17 +0100 Subject: [PATCH 51/62] Add tags to queries --- .../src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql | 1 + .../RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql | 1 + c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql | 1 + 3 files changed, 3 insertions(+) diff --git a/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql b/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql index 68c5faeb1b..1e32793c3f 100644 --- a/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql +++ b/c/misra/src/rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql @@ -8,6 +8,7 @@ * @problem.severity recommendation * @tags external/misra/id/rule-17-10 * correctness + * external/misra/c/2012/amendment3 * external/misra/obligation/required */ diff --git a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql index 90cb1af7c2..4dd939effe 100644 --- a/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql +++ b/c/misra/src/rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql @@ -7,6 +7,7 @@ * @problem.severity recommendation * @tags external/misra/id/rule-17-11 * correctness + * external/misra/c/2012/amendment3 * external/misra/obligation/advisory */ diff --git a/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql b/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql index 360be01b7c..dedac9da9e 100644 --- a/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql +++ b/c/misra/src/rules/RULE-17-9/ReturnStatementInNoreturnFunction.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-17-9 * correctness + * external/misra/c/2012/amendment3 * external/misra/obligation/mandatory */ From 46d09db02ea2ce17a6a6996039dddb9a969592dd Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 24 Sep 2024 10:32:11 -0700 Subject: [PATCH 52/62] First pass on 17-12, 17-13, both facing extractor issues. --- .../FunctionAddressesShouldAddressOperator.ql | 83 ++++++++++ .../DisallowedFunctionTypeQualifier.ql | 147 ++++++++++++++++++ ...ionAddressesShouldAddressOperator.expected | 18 +++ ...nctionAddressesShouldAddressOperator.qlref | 1 + c/misra/test/rules/RULE-17-12/test.c | 106 +++++++++++++ .../DisallowedFunctionTypeQualifier.expected | 1 + .../DisallowedFunctionTypeQualifier.qlref | 1 + c/misra/test/rules/RULE-17-13/test.c | 56 +++++++ .../cpp/exclusions/c/FunctionTypes.qll | 44 ++++++ .../cpp/exclusions/c/RuleMetadata.qll | 3 + rule_packages/c/FunctionTypes.json | 42 +++++ 11 files changed, 502 insertions(+) create mode 100644 c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql create mode 100644 c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql create mode 100644 c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected create mode 100644 c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.qlref create mode 100644 c/misra/test/rules/RULE-17-12/test.c create mode 100644 c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected create mode 100644 c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref create mode 100644 c/misra/test/rules/RULE-17-13/test.c create mode 100644 cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll create mode 100644 rule_packages/c/FunctionTypes.json diff --git a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql new file mode 100644 index 0000000000..4c3386c68b --- /dev/null +++ b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql @@ -0,0 +1,83 @@ +/** + * @id c/misra/function-addresses-should-address-operator + * @name RULE-17-12: A function identifier should only be called with a parenthesized parameter list or used with a & + * @description A function identifier should only be called with a parenthesized parameter list or + * used with a & (address-of). + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-17-12 + * readability + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.c.misra + +abstract class AddressOfFunction extends Expr { + abstract predicate isImplicitlyAddressed(); + + abstract string getFuncName(); +} + +class FunctionTypeAccess extends FunctionAccess, AddressOfFunction { + + predicate isImmediatelyParenthesized() { + exists(ParenthesisExpr parens | parens.getExpr() = this) + } + + predicate isExplicitlyAddressed() { + getParent() instanceof AddressOfExpr and + not isImmediatelyParenthesized() + } + + override predicate isImplicitlyAddressed() { + not isExplicitlyAddressed() + } + + override string getFuncName() { + result = getTarget().getName() + } +} + +/* +class IndirectFunctionCall extends FunctionCall, AddressOfFunction { + override predicate isImplicitlyAddressed() { + getConversion+() instanceof ParenthesisExpr + } + + override string getFuncName() { + result = getTarget().getName() + } +} + */ + +class MacroArgTakesFunction extends AddressOfFunction { + MacroInvocation m; + MacroArgTakesFunction() { + m.getExpr() = this + } + + override predicate isImplicitlyAddressed() { + any() + } + + string getProp() { + result = m.getExpandedArgument(_) + and this.get + } + + override string getFuncName() { + result = "a macro argument" + } + +} + +from AddressOfFunction funcAddr +where + not isExcluded(funcAddr, FunctionTypesPackage::functionAddressesShouldAddressOperatorQuery()) and + //not funcAccess.isImmediatelyCalled() and + //not funcAccess.isExplicitlyAddressed() + funcAddr.isImplicitlyAddressed() +select + funcAddr, "The address of function " + funcAddr.getFuncName() + " is taken without the & operator." \ No newline at end of file diff --git a/c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql b/c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql new file mode 100644 index 0000000000..a40dadef6c --- /dev/null +++ b/c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql @@ -0,0 +1,147 @@ +/** + * @id c/misra/disallowed-function-type-qualifier + * @name RULE-17-13: A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic) + * @description The behavior of type qualifiers on a function type is undefined. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-17-13 + * correctness + * external/misra/obligation/required + */ + +import cpp +import codingstandards.c.misra + +//from DeclarationEntry decl, Type type //, Specifier specifier +//where +// not isExcluded(decl, FunctionTypesPackage::disallowedFunctionTypeQualifierQuery()) and +// //decl.getType() instanceof FunctionPointerType and +// //decl.getType().(FunctionPointerType).hasSpecifier(specifier) +// (type = decl.getType().getUnderlyingType*() +// or type = decl.getType()) +// and +// //specifier = type.getASpecifier() +// any() +//select decl, type //, specifier // "The behavior of type qualifier " + specifier + " on a function type is undefined." + +newtype TDeclaredFunction = + TFunctionDeclaration(Declaration declaration) + +abstract class DeclaredFunction extends TDeclaredFunction { + abstract string toString(); +} + +predicate isConstFunction(Type type) { + (type.getASpecifier().getName() = "const" + or type.isConst()) + and isFunctionType(type) + or isConstFunction(type.getUnderlyingType()) +} + +predicate isFunctionType(Type type) { + type instanceof FunctionPointerType + or isFunctionType(type.getUnderlyingType()) +} + +predicate declaresConstFunction(DeclarationEntry entry) { + (entry.getDeclaration().getASpecifier().getName() = "const" + and isFunctionType(entry.getType())) + or isConstFunction(entry.getType()) +} + +class QualifiableRoutineType extends RoutineType, QualifiableType { + override string explainQualifiers() { + result = "func{" + + specifiersOf(this) + this.getReturnType().(QualifiableType).explainQualifiers() + + " (" + + paramString(0) + + ")}" + } + + string paramString(int i) { + i = 0 and result = "" and not exists(this.getAParameterType()) + or + ( + if i < max(int j | exists(this.getParameterType(j))) + then + // Not the last one + result = this.getParameterType(i).(QualifiableType).explainQualifiers() + "," + this.paramString(i + 1) + else + // Last parameter + result = this.getParameterType(i).(QualifiableType).explainQualifiers() + ) + } +} + +class QualifiableIntType extends IntType, QualifiableType { + override string explainQualifiers() { + result = specifiersOf(this) + " " + this.toString() + } +} + +class QualifiablePointerType extends PointerType, QualifiableType { + override string explainQualifiers() { + result = "{" + + specifiersOf(this) + + " pointer to " + + this.getBaseType().(QualifiableType).explainQualifiers() + + "}" + } +} + +class QualifiableType extends Type { + string explainQualifiers() { + result = "Unimplemented explainQualifiers for type(s): " + concat(string s | s = getAQlClass() | s, ",") + } +} + +class QualifiableTypedefType extends TypedefType, QualifiableType { + override string explainQualifiers() { + result = "{ typedef " + + specifiersOf(this) + + " " + + this.getBaseType().(QualifiableType).explainQualifiers() + + "}" + } +} + +class QualifiableSpecifiedType extends SpecifiedType, QualifiableType { + override string explainQualifiers() { + result = "{" + + specifiersOf(this) + + " " + + this.getBaseType().(QualifiableType).explainQualifiers() + + "}" + } +} + +string typeString(Type t) { + //if + // t instanceof CTypedefType + // then result = t.(CTypedefType).explain() + "specs:" + specifiersOf(t.(CTypedefType).getBaseType()) + "/" + typeString(t.(CTypedefType).getBaseType()) + // else + //result = concat(string s | s = t.getAQlClass() | s, ",") + result = t.(QualifiableType).explainQualifiers() +} + +string specifiersOf(Type t) { + result = concat(Specifier s | s = t.getASpecifier()| s.getName(), ", ") +} + +string declSpecifiersOf(Declaration d) { + result = concat(Specifier s | s = d.getASpecifier()| s.getName(), ", ") +} + +string underlying(Type t) { + exists(Type u | u = t.getUnderlyingType() | result = u.toString()) + or result = "[no underlying]" + +} + +from DeclarationEntry entry +select entry, entry.getType(), typeString(entry.getType()), declSpecifiersOf(entry.getDeclaration()), specifiersOf(entry.getType()) + +//from Type t +//where any()//isFunctionType(t) +//select t, specifiersOf(t), underlying(t) \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected new file mode 100644 index 0000000000..1cc92e95e1 --- /dev/null +++ b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected @@ -0,0 +1,18 @@ +| test.c:15:25:15:29 | func2 | The address of function func2 is taken without the & operator. | +| test.c:16:27:16:31 | func3 | The address of function func3 is taken without the & operator. | +| test.c:22:16:22:20 | func1 | The address of function func1 is taken without the & operator. | +| test.c:38:5:38:9 | func1 | The address of function func1 is taken without the & operator. | +| test.c:39:5:39:9 | func2 | The address of function func2 is taken without the & operator. | +| test.c:47:7:47:11 | func1 | The address of function func1 is taken without the & operator. | +| test.c:48:7:48:11 | func2 | The address of function func2 is taken without the & operator. | +| test.c:57:15:57:19 | func1 | The address of function func1 is taken without the & operator. | +| test.c:58:23:58:27 | func2 | The address of function func2 is taken without the & operator. | +| test.c:59:15:59:19 | func1 | The address of function func1 is taken without the & operator. | +| test.c:59:22:59:26 | func2 | The address of function func2 is taken without the & operator. | +| test.c:67:13:67:17 | func1 | The address of function func1 is taken without the & operator. | +| test.c:68:14:68:18 | func1 | The address of function func1 is taken without the & operator. | +| test.c:69:14:69:18 | func1 | The address of function func1 is taken without the & operator. | +| test.c:71:20:71:24 | func1 | The address of function func1 is taken without the & operator. | +| test.c:72:20:72:24 | func1 | The address of function func1 is taken without the & operator. | +| test.c:76:20:76:24 | func1 | The address of function func1 is taken without the & operator. | +| test.c:77:20:77:24 | func1 | The address of function func1 is taken without the & operator. | diff --git a/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.qlref b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.qlref new file mode 100644 index 0000000000..f0a4753620 --- /dev/null +++ b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.qlref @@ -0,0 +1 @@ +rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-12/test.c b/c/misra/test/rules/RULE-17-12/test.c new file mode 100644 index 0000000000..1c580f917e --- /dev/null +++ b/c/misra/test/rules/RULE-17-12/test.c @@ -0,0 +1,106 @@ +void func1() {} +void func2(int x, char* y) {} + +typedef struct {} s; + +int func3() { + return 0; +} + +typedef void (*func_ptr_t1)(); +typedef void (*func_ptr_t2)(int x, char* y); +typedef s (*func_ptr_t3)(); + +func_ptr_t1 func_ptr1 = &func1; // COMPLIANT +func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT +func_ptr_t3 func_ptr3 = &(func3); // NON-COMPLIANT + +void take_func(func_ptr_t1 f1, func_ptr_t2 f2); + +func_ptr_t1 returns_func(int x) { + if (x == 0) { + return func1; // NON-COMPLIANT + } else if (x == 1) { + return &func1; // COMPLIANT + } + + return returns_func(0); // COMPLIANT +} + +#define MACRO_IDENTITY(f) (f) +#define MACRO_INVOKE_RISKY(f) (f()) +#define MACRO_INVOKE_IMPROVED(f) ((f)()) + +void test() { + func1(); // COMPLIANT + func2(1, "hello"); // COMPLIANT + + func1; // NON-COMPLIANT + func2; // NON-COMPLIANT + + &func1; // COMPLIANT + &func2; // COMPLIANT + + (func1)(); // COMPLIANT + (func2)(1, "hello"); // COMPLIANT + + &(func1); // NON-COMPLIANT + &(func2); // NON-COMPLIANT + + (&func1)(); // COMPLIANT + (&func2)(1, "hello"); // COMPLIANT + + (func1()); // COMPLIANT + (func2(1, "hello")); // COMPLIANT + + take_func(&func1, &func2); // COMPLIANT + take_func(func1, &func2); // NON-COMPLIANT + take_func(&func1, func2); // NON-COMPLIANT + take_func(func1, func2); // NON-COMPLIANT + + returns_func(0); // COMPLIANT + returns_func(0)(); // COMPLIANT + (returns_func(0))(); // COMPLIANT + + (void*) &func1; // COMPLIANT + (void*) (&func1); // COMPLIANT + (void*) func1; // NON-COMPLIANT + (void*) (func1); // NON-COMPLIANT + ((void*) func1); // NON-COMPLIANT + + MACRO_IDENTITY(func1); // NON-COMPLIANT + MACRO_IDENTITY(func1)(); // NON-COMPLIANT + MACRO_IDENTITY(&func1); // COMPLIANT + MACRO_IDENTITY(&func1)(); // COMPLIANT + + MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT + MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT + MACRO_INVOKE_IMPROVED(&func3); // COMPLIANT + + // Function pointers are exempt from this rule. + func_ptr1(); // COMPLIANT + func_ptr2(1, "hello"); // COMPLIANT + func_ptr1; // COMPLIANT + func_ptr2; // COMPLIANT + &func_ptr1; // COMPLIANT + &func_ptr2; // COMPLIANT + (func_ptr1)(); // COMPLIANT + (func_ptr2)(1, "hello"); // COMPLIANT + (*func_ptr1)(); // COMPLIANT + (*func_ptr2)(1, "hello"); // COMPLIANT + take_func(func_ptr1, func_ptr2); // COMPLIANT + (void*) func_ptr1; // COMPLIANT + (void*) &func_ptr1; // COMPLIANT + (void*) (&func_ptr1); // COMPLIANT + (void*) func_ptr1; // COMPLIANT + (void*) (func_ptr1); // COMPLIANT + ((void*) func_ptr1); // COMPLIANT + MACRO_IDENTITY(func_ptr1); // COMPLIANT + MACRO_IDENTITY(func_ptr1)(); // COMPLIANT + MACRO_IDENTITY(&func_ptr1); // COMPLIANT + (*MACRO_IDENTITY(&func_ptr1))(); // COMPLIANT + MACRO_INVOKE_RISKY(func_ptr3); // COMPLIANT + MACRO_INVOKE_IMPROVED(func_ptr3); // COMPLIANT + MACRO_INVOKE_IMPROVED(*&func_ptr3); // COMPLIANT + +} \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected b/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected new file mode 100644 index 0000000000..2ec1a0ac6c --- /dev/null +++ b/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected @@ -0,0 +1 @@ +No expected results have yet been specified \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref b/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref new file mode 100644 index 0000000000..cbf7c583ec --- /dev/null +++ b/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref @@ -0,0 +1 @@ +rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-13/test.c b/c/misra/test/rules/RULE-17-13/test.c new file mode 100644 index 0000000000..8326b30a28 --- /dev/null +++ b/c/misra/test/rules/RULE-17-13/test.c @@ -0,0 +1,56 @@ +// semmle-extractor-options: --language=c -std=c99 +const int x; // COMPLIANT +const int f_ret_const_int(void); // COMPLIANT +const int* f_ret_const_int_ptr(void); // COMPLIANT + +// Basic function typedefs +typedef int ftype_ret_int(void); +typedef const int ftype_ret_const_int(void); // COMPLIANT +typedef const int* ftype_ret_const_int_ptr(void); // COMPLIANT +typedef int const* ftype_ret_int_const_ptr(void); // COMPLIANT + +// Typedefs that use function typedefs +typedef ftype_ret_int ftype_ret_int2; // COMPLIANT +typedef const ftype_ret_int *ptr_const_ftype_ret_int; // NON-COMPLIANT +typedef ftype_ret_int *const const_ptr_ftype_ret_int; // COMPLIANT +typedef ftype_ret_int const* const_ptr_ftype_ret_int_; // NON-COMPLIANT + +// Test all qualifiers +typedef const ftype_ret_int const_ftype_ret_int; // NON-COMPLIANT +typedef volatile ftype_ret_int volatile_ftype_ret_int; // NON-COMPLIANT +typedef _Atomic ftype_ret_int atomic_ftype_ret_int; // NON-COMPLIANT +//extern restrict ftype_ret_int restrict_ftype_ret_int; // NON-COMPLIANT + +// Test parameters of declaration specifiers +typedef void (*take_ftype_ret_int)(ftype_ret_int); // COMPLIANT +typedef void (*take_const_ftype_ret_int)(const ftype_ret_int); // NON-COMPLIANT +typedef void (*take_ptr_ftype_ret_int)(ftype_ret_int*); // COMPLIANT +typedef void (*take_ptr_const_ftype_ret_int)(const ftype_ret_int *); // NON-COMPLIANT +typedef void (*take_const_ptr_ftype_ret_int)(ftype_ret_int const *); // COMPLIANT + +// Test return types of declaration specifiers +typedef ftype_ret_int* (return_ftype_ret_int)(void); // COMPLIANT +typedef const ftype_ret_int* (return_ftype_ret_int)(void); // NON-COMPLIANT +typedef ftype_ret_int const* (return_ftype_ret_int)(void); // COMPLIANT + +// Other storage class specifiers +extern const ftype_ret_int extern_ftype; // NON-COMPLIANT +extern const ftype_ret_int *extern_const_ftype_type; // NON-COMPLIANT +extern ftype_ret_int const * extern_ftype_const_ptr; // COMPLIANT + +// Other declarations +void param_list( + const ftype_ret_int *param_ftype, // NON-COMPLIANT + const ftype_ret_int *param_const_ftype_type, // NON-COMPLIANT + ftype_ret_int const *param_ftype_const_ptr // COMPLIANT +) { + const ftype_ret_int *var_ftype; // NON-COMPLIANT + const ftype_ret_int *var_const_ftype_type; // NON-COMPLIANT + ftype_ret_int const *var_ftype_const_ptr; // COMPLIANT + + struct TestStruct { + const ftype_ret_int *struct_ftype; // NON-COMPLIANT + const ftype_ret_int *struct_const_ftype_type; // NON-COMPLIANT + ftype_ret_int const *struct_ftype_const_ptr; // COMPLIANT + }; +} diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll new file mode 100644 index 0000000000..176b9871d3 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll @@ -0,0 +1,44 @@ +//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ +import cpp +import RuleMetadata +import codingstandards.cpp.exclusions.RuleMetadata + +newtype FunctionTypesQuery = + TFunctionAddressesShouldAddressOperatorQuery() or + TDisallowedFunctionTypeQualifierQuery() + +predicate isFunctionTypesQueryMetadata(Query query, string queryId, string ruleId, string category) { + query = + // `Query` instance for the `functionAddressesShouldAddressOperator` query + FunctionTypesPackage::functionAddressesShouldAddressOperatorQuery() and + queryId = + // `@id` for the `functionAddressesShouldAddressOperator` query + "c/misra/function-addresses-should-address-operator" and + ruleId = "RULE-17-12" and + category = "advisory" + or + query = + // `Query` instance for the `disallowedFunctionTypeQualifier` query + FunctionTypesPackage::disallowedFunctionTypeQualifierQuery() and + queryId = + // `@id` for the `disallowedFunctionTypeQualifier` query + "c/misra/disallowed-function-type-qualifier" and + ruleId = "RULE-17-13" and + category = "required" +} + +module FunctionTypesPackage { + Query functionAddressesShouldAddressOperatorQuery() { + //autogenerate `Query` type + result = + // `Query` type for `functionAddressesShouldAddressOperator` query + TQueryC(TFunctionTypesPackageQuery(TFunctionAddressesShouldAddressOperatorQuery())) + } + + Query disallowedFunctionTypeQualifierQuery() { + //autogenerate `Query` type + result = + // `Query` type for `disallowedFunctionTypeQualifier` query + TQueryC(TFunctionTypesPackageQuery(TDisallowedFunctionTypeQualifierQuery())) + } +} diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll index b10fbf0a2f..581585da5c 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll @@ -29,6 +29,7 @@ import Declarations8 import EssentialTypes import Expressions import FloatingTypes +import FunctionTypes import IO1 import IO2 import IO3 @@ -102,6 +103,7 @@ newtype TCQuery = TEssentialTypesPackageQuery(EssentialTypesQuery q) or TExpressionsPackageQuery(ExpressionsQuery q) or TFloatingTypesPackageQuery(FloatingTypesQuery q) or + TFunctionTypesPackageQuery(FunctionTypesQuery q) or TIO1PackageQuery(IO1Query q) or TIO2PackageQuery(IO2Query q) or TIO3PackageQuery(IO3Query q) or @@ -175,6 +177,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat isEssentialTypesQueryMetadata(query, queryId, ruleId, category) or isExpressionsQueryMetadata(query, queryId, ruleId, category) or isFloatingTypesQueryMetadata(query, queryId, ruleId, category) or + isFunctionTypesQueryMetadata(query, queryId, ruleId, category) or isIO1QueryMetadata(query, queryId, ruleId, category) or isIO2QueryMetadata(query, queryId, ruleId, category) or isIO3QueryMetadata(query, queryId, ruleId, category) or diff --git a/rule_packages/c/FunctionTypes.json b/rule_packages/c/FunctionTypes.json new file mode 100644 index 0000000000..bfa96d09eb --- /dev/null +++ b/rule_packages/c/FunctionTypes.json @@ -0,0 +1,42 @@ +{ + "MISRA-C-2012": { + "RULE-17-12": { + "properties": { + "obligation": "advisory" + }, + "queries": [ + { + "description": "A function identifier should only be called with a parenthesized parameter list or used with a & (address-of).", + "kind": "problem", + "name": "A function identifier should only be called with a parenthesized parameter list or used with a &", + "precision": "very-high", + "severity": "error", + "short_name": "FunctionAddressesShouldAddressOperator", + "tags": [ + "readability" + ] + } + ], + "title": "A function identifier should only be called with a parenthesized parameter list or used with a & (address-of)" + }, + "RULE-17-13": { + "properties": { + "obligation": "required" + }, + "queries": [ + { + "description": "The behavior of type qualifiers on a function type is undefined.", + "kind": "problem", + "name": "A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic)", + "precision": "very-high", + "severity": "error", + "short_name": "DisallowedFunctionTypeQualifier", + "tags": [ + "correctness" + ] + } + ], + "title": "A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic)" + } + } +} \ No newline at end of file From d798fc87149908f801fceb4d495888d9d909ff08 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Fri, 27 Sep 2024 15:34:14 -0700 Subject: [PATCH 53/62] Remove 17-13, simpler implementation for 17-12. --- .../FunctionAddressesShouldAddressOperator.ql | 73 ++------- .../DisallowedFunctionTypeQualifier.ql | 147 ------------------ ...ionAddressesShouldAddressOperator.expected | 23 ++- c/misra/test/rules/RULE-17-12/test.c | 9 +- .../DisallowedFunctionTypeQualifier.expected | 1 - .../DisallowedFunctionTypeQualifier.qlref | 1 - c/misra/test/rules/RULE-17-13/test.c | 56 ------- .../cpp/exclusions/c/FunctionTypes.qll | 20 +-- rule_packages/c/FunctionTypes.json | 14 +- 9 files changed, 27 insertions(+), 317 deletions(-) delete mode 100644 c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql delete mode 100644 c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected delete mode 100644 c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref delete mode 100644 c/misra/test/rules/RULE-17-13/test.c diff --git a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql index 4c3386c68b..96c466150b 100644 --- a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql +++ b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql @@ -14,70 +14,15 @@ import cpp import codingstandards.c.misra -abstract class AddressOfFunction extends Expr { - abstract predicate isImplicitlyAddressed(); - - abstract string getFuncName(); -} - -class FunctionTypeAccess extends FunctionAccess, AddressOfFunction { - - predicate isImmediatelyParenthesized() { - exists(ParenthesisExpr parens | parens.getExpr() = this) - } - - predicate isExplicitlyAddressed() { - getParent() instanceof AddressOfExpr and - not isImmediatelyParenthesized() - } - - override predicate isImplicitlyAddressed() { - not isExplicitlyAddressed() - } - - override string getFuncName() { - result = getTarget().getName() - } -} - -/* -class IndirectFunctionCall extends FunctionCall, AddressOfFunction { - override predicate isImplicitlyAddressed() { - getConversion+() instanceof ParenthesisExpr - } - - override string getFuncName() { - result = getTarget().getName() - } -} - */ - -class MacroArgTakesFunction extends AddressOfFunction { - MacroInvocation m; - MacroArgTakesFunction() { - m.getExpr() = this - } - - override predicate isImplicitlyAddressed() { - any() - } - - string getProp() { - result = m.getExpandedArgument(_) - and this.get - } - - override string getFuncName() { - result = "a macro argument" - } - +predicate isImplicitlyAddressed(FunctionAccess access) { + not access.getParent() instanceof AddressOfExpr or + exists(ParenthesisExpr parens | parens.getExpr() = access) } -from AddressOfFunction funcAddr +from FunctionAccess funcAccess where - not isExcluded(funcAddr, FunctionTypesPackage::functionAddressesShouldAddressOperatorQuery()) and - //not funcAccess.isImmediatelyCalled() and - //not funcAccess.isExplicitlyAddressed() - funcAddr.isImplicitlyAddressed() -select - funcAddr, "The address of function " + funcAddr.getFuncName() + " is taken without the & operator." \ No newline at end of file + not isExcluded(funcAccess, FunctionTypesPackage::functionAddressesShouldAddressOperatorQuery()) and + isImplicitlyAddressed(funcAccess) +select funcAccess, + "The address of function " + funcAccess.getTarget().getName() + + " is taken without the & operator." diff --git a/c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql b/c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql deleted file mode 100644 index a40dadef6c..0000000000 --- a/c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql +++ /dev/null @@ -1,147 +0,0 @@ -/** - * @id c/misra/disallowed-function-type-qualifier - * @name RULE-17-13: A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic) - * @description The behavior of type qualifiers on a function type is undefined. - * @kind problem - * @precision very-high - * @problem.severity error - * @tags external/misra/id/rule-17-13 - * correctness - * external/misra/obligation/required - */ - -import cpp -import codingstandards.c.misra - -//from DeclarationEntry decl, Type type //, Specifier specifier -//where -// not isExcluded(decl, FunctionTypesPackage::disallowedFunctionTypeQualifierQuery()) and -// //decl.getType() instanceof FunctionPointerType and -// //decl.getType().(FunctionPointerType).hasSpecifier(specifier) -// (type = decl.getType().getUnderlyingType*() -// or type = decl.getType()) -// and -// //specifier = type.getASpecifier() -// any() -//select decl, type //, specifier // "The behavior of type qualifier " + specifier + " on a function type is undefined." - -newtype TDeclaredFunction = - TFunctionDeclaration(Declaration declaration) - -abstract class DeclaredFunction extends TDeclaredFunction { - abstract string toString(); -} - -predicate isConstFunction(Type type) { - (type.getASpecifier().getName() = "const" - or type.isConst()) - and isFunctionType(type) - or isConstFunction(type.getUnderlyingType()) -} - -predicate isFunctionType(Type type) { - type instanceof FunctionPointerType - or isFunctionType(type.getUnderlyingType()) -} - -predicate declaresConstFunction(DeclarationEntry entry) { - (entry.getDeclaration().getASpecifier().getName() = "const" - and isFunctionType(entry.getType())) - or isConstFunction(entry.getType()) -} - -class QualifiableRoutineType extends RoutineType, QualifiableType { - override string explainQualifiers() { - result = "func{" - + specifiersOf(this) + this.getReturnType().(QualifiableType).explainQualifiers() - + " (" - + paramString(0) - + ")}" - } - - string paramString(int i) { - i = 0 and result = "" and not exists(this.getAParameterType()) - or - ( - if i < max(int j | exists(this.getParameterType(j))) - then - // Not the last one - result = this.getParameterType(i).(QualifiableType).explainQualifiers() + "," + this.paramString(i + 1) - else - // Last parameter - result = this.getParameterType(i).(QualifiableType).explainQualifiers() - ) - } -} - -class QualifiableIntType extends IntType, QualifiableType { - override string explainQualifiers() { - result = specifiersOf(this) + " " + this.toString() - } -} - -class QualifiablePointerType extends PointerType, QualifiableType { - override string explainQualifiers() { - result = "{" - + specifiersOf(this) - + " pointer to " - + this.getBaseType().(QualifiableType).explainQualifiers() - + "}" - } -} - -class QualifiableType extends Type { - string explainQualifiers() { - result = "Unimplemented explainQualifiers for type(s): " + concat(string s | s = getAQlClass() | s, ",") - } -} - -class QualifiableTypedefType extends TypedefType, QualifiableType { - override string explainQualifiers() { - result = "{ typedef " - + specifiersOf(this) - + " " - + this.getBaseType().(QualifiableType).explainQualifiers() - + "}" - } -} - -class QualifiableSpecifiedType extends SpecifiedType, QualifiableType { - override string explainQualifiers() { - result = "{" - + specifiersOf(this) - + " " - + this.getBaseType().(QualifiableType).explainQualifiers() - + "}" - } -} - -string typeString(Type t) { - //if - // t instanceof CTypedefType - // then result = t.(CTypedefType).explain() + "specs:" + specifiersOf(t.(CTypedefType).getBaseType()) + "/" + typeString(t.(CTypedefType).getBaseType()) - // else - //result = concat(string s | s = t.getAQlClass() | s, ",") - result = t.(QualifiableType).explainQualifiers() -} - -string specifiersOf(Type t) { - result = concat(Specifier s | s = t.getASpecifier()| s.getName(), ", ") -} - -string declSpecifiersOf(Declaration d) { - result = concat(Specifier s | s = d.getASpecifier()| s.getName(), ", ") -} - -string underlying(Type t) { - exists(Type u | u = t.getUnderlyingType() | result = u.toString()) - or result = "[no underlying]" - -} - -from DeclarationEntry entry -select entry, entry.getType(), typeString(entry.getType()), declSpecifiersOf(entry.getDeclaration()), specifiersOf(entry.getType()) - -//from Type t -//where any()//isFunctionType(t) -//select t, specifiersOf(t), underlying(t) \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected index 1cc92e95e1..d4862c5978 100644 --- a/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected +++ b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected @@ -1,18 +1,15 @@ | test.c:15:25:15:29 | func2 | The address of function func2 is taken without the & operator. | | test.c:16:27:16:31 | func3 | The address of function func3 is taken without the & operator. | | test.c:22:16:22:20 | func1 | The address of function func1 is taken without the & operator. | -| test.c:38:5:38:9 | func1 | The address of function func1 is taken without the & operator. | -| test.c:39:5:39:9 | func2 | The address of function func2 is taken without the & operator. | -| test.c:47:7:47:11 | func1 | The address of function func1 is taken without the & operator. | -| test.c:48:7:48:11 | func2 | The address of function func2 is taken without the & operator. | -| test.c:57:15:57:19 | func1 | The address of function func1 is taken without the & operator. | -| test.c:58:23:58:27 | func2 | The address of function func2 is taken without the & operator. | -| test.c:59:15:59:19 | func1 | The address of function func1 is taken without the & operator. | -| test.c:59:22:59:26 | func2 | The address of function func2 is taken without the & operator. | -| test.c:67:13:67:17 | func1 | The address of function func1 is taken without the & operator. | -| test.c:68:14:68:18 | func1 | The address of function func1 is taken without the & operator. | +| test.c:39:5:39:9 | func1 | The address of function func1 is taken without the & operator. | +| test.c:40:5:40:9 | func2 | The address of function func2 is taken without the & operator. | +| test.c:48:7:48:11 | func1 | The address of function func1 is taken without the & operator. | +| test.c:49:7:49:11 | func2 | The address of function func2 is taken without the & operator. | +| test.c:58:15:58:19 | func1 | The address of function func1 is taken without the & operator. | +| test.c:59:23:59:27 | func2 | The address of function func2 is taken without the & operator. | +| test.c:60:15:60:19 | func1 | The address of function func1 is taken without the & operator. | +| test.c:60:22:60:26 | func2 | The address of function func2 is taken without the & operator. | +| test.c:68:13:68:17 | func1 | The address of function func1 is taken without the & operator. | | test.c:69:14:69:18 | func1 | The address of function func1 is taken without the & operator. | -| test.c:71:20:71:24 | func1 | The address of function func1 is taken without the & operator. | +| test.c:70:14:70:18 | func1 | The address of function func1 is taken without the & operator. | | test.c:72:20:72:24 | func1 | The address of function func1 is taken without the & operator. | -| test.c:76:20:76:24 | func1 | The address of function func1 is taken without the & operator. | -| test.c:77:20:77:24 | func1 | The address of function func1 is taken without the & operator. | diff --git a/c/misra/test/rules/RULE-17-12/test.c b/c/misra/test/rules/RULE-17-12/test.c index 1c580f917e..4cfe1f6de6 100644 --- a/c/misra/test/rules/RULE-17-12/test.c +++ b/c/misra/test/rules/RULE-17-12/test.c @@ -30,6 +30,7 @@ func_ptr_t1 returns_func(int x) { #define MACRO_IDENTITY(f) (f) #define MACRO_INVOKE_RISKY(f) (f()) #define MACRO_INVOKE_IMPROVED(f) ((f)()) +#define MACRO_INVOKE_AND_USE_AS_TOKEN(f) f(0, #f) void test() { func1(); // COMPLIANT @@ -69,14 +70,16 @@ void test() { ((void*) func1); // NON-COMPLIANT MACRO_IDENTITY(func1); // NON-COMPLIANT - MACRO_IDENTITY(func1)(); // NON-COMPLIANT + MACRO_IDENTITY(func1)(); // NON-COMPLIANT[FALSE NEGATIVE] MACRO_IDENTITY(&func1); // COMPLIANT MACRO_IDENTITY(&func1)(); // COMPLIANT - MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT - MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT + MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT[FALSE NEGATIVE] + MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT[FALSE NEGATIVE] MACRO_INVOKE_IMPROVED(&func3); // COMPLIANT + MACRO_INVOKE_AND_USE_AS_TOKEN(func1); // COMPLIANT + // Function pointers are exempt from this rule. func_ptr1(); // COMPLIANT func_ptr2(1, "hello"); // COMPLIANT diff --git a/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected b/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected deleted file mode 100644 index 2ec1a0ac6c..0000000000 --- a/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected +++ /dev/null @@ -1 +0,0 @@ -No expected results have yet been specified \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref b/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref deleted file mode 100644 index cbf7c583ec..0000000000 --- a/c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-17-13/test.c b/c/misra/test/rules/RULE-17-13/test.c deleted file mode 100644 index 8326b30a28..0000000000 --- a/c/misra/test/rules/RULE-17-13/test.c +++ /dev/null @@ -1,56 +0,0 @@ -// semmle-extractor-options: --language=c -std=c99 -const int x; // COMPLIANT -const int f_ret_const_int(void); // COMPLIANT -const int* f_ret_const_int_ptr(void); // COMPLIANT - -// Basic function typedefs -typedef int ftype_ret_int(void); -typedef const int ftype_ret_const_int(void); // COMPLIANT -typedef const int* ftype_ret_const_int_ptr(void); // COMPLIANT -typedef int const* ftype_ret_int_const_ptr(void); // COMPLIANT - -// Typedefs that use function typedefs -typedef ftype_ret_int ftype_ret_int2; // COMPLIANT -typedef const ftype_ret_int *ptr_const_ftype_ret_int; // NON-COMPLIANT -typedef ftype_ret_int *const const_ptr_ftype_ret_int; // COMPLIANT -typedef ftype_ret_int const* const_ptr_ftype_ret_int_; // NON-COMPLIANT - -// Test all qualifiers -typedef const ftype_ret_int const_ftype_ret_int; // NON-COMPLIANT -typedef volatile ftype_ret_int volatile_ftype_ret_int; // NON-COMPLIANT -typedef _Atomic ftype_ret_int atomic_ftype_ret_int; // NON-COMPLIANT -//extern restrict ftype_ret_int restrict_ftype_ret_int; // NON-COMPLIANT - -// Test parameters of declaration specifiers -typedef void (*take_ftype_ret_int)(ftype_ret_int); // COMPLIANT -typedef void (*take_const_ftype_ret_int)(const ftype_ret_int); // NON-COMPLIANT -typedef void (*take_ptr_ftype_ret_int)(ftype_ret_int*); // COMPLIANT -typedef void (*take_ptr_const_ftype_ret_int)(const ftype_ret_int *); // NON-COMPLIANT -typedef void (*take_const_ptr_ftype_ret_int)(ftype_ret_int const *); // COMPLIANT - -// Test return types of declaration specifiers -typedef ftype_ret_int* (return_ftype_ret_int)(void); // COMPLIANT -typedef const ftype_ret_int* (return_ftype_ret_int)(void); // NON-COMPLIANT -typedef ftype_ret_int const* (return_ftype_ret_int)(void); // COMPLIANT - -// Other storage class specifiers -extern const ftype_ret_int extern_ftype; // NON-COMPLIANT -extern const ftype_ret_int *extern_const_ftype_type; // NON-COMPLIANT -extern ftype_ret_int const * extern_ftype_const_ptr; // COMPLIANT - -// Other declarations -void param_list( - const ftype_ret_int *param_ftype, // NON-COMPLIANT - const ftype_ret_int *param_const_ftype_type, // NON-COMPLIANT - ftype_ret_int const *param_ftype_const_ptr // COMPLIANT -) { - const ftype_ret_int *var_ftype; // NON-COMPLIANT - const ftype_ret_int *var_const_ftype_type; // NON-COMPLIANT - ftype_ret_int const *var_ftype_const_ptr; // COMPLIANT - - struct TestStruct { - const ftype_ret_int *struct_ftype; // NON-COMPLIANT - const ftype_ret_int *struct_const_ftype_type; // NON-COMPLIANT - ftype_ret_int const *struct_ftype_const_ptr; // COMPLIANT - }; -} diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll index 176b9871d3..3d6faadb42 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll @@ -3,9 +3,7 @@ import cpp import RuleMetadata import codingstandards.cpp.exclusions.RuleMetadata -newtype FunctionTypesQuery = - TFunctionAddressesShouldAddressOperatorQuery() or - TDisallowedFunctionTypeQualifierQuery() +newtype FunctionTypesQuery = TFunctionAddressesShouldAddressOperatorQuery() predicate isFunctionTypesQueryMetadata(Query query, string queryId, string ruleId, string category) { query = @@ -16,15 +14,6 @@ predicate isFunctionTypesQueryMetadata(Query query, string queryId, string ruleI "c/misra/function-addresses-should-address-operator" and ruleId = "RULE-17-12" and category = "advisory" - or - query = - // `Query` instance for the `disallowedFunctionTypeQualifier` query - FunctionTypesPackage::disallowedFunctionTypeQualifierQuery() and - queryId = - // `@id` for the `disallowedFunctionTypeQualifier` query - "c/misra/disallowed-function-type-qualifier" and - ruleId = "RULE-17-13" and - category = "required" } module FunctionTypesPackage { @@ -34,11 +23,4 @@ module FunctionTypesPackage { // `Query` type for `functionAddressesShouldAddressOperator` query TQueryC(TFunctionTypesPackageQuery(TFunctionAddressesShouldAddressOperatorQuery())) } - - Query disallowedFunctionTypeQualifierQuery() { - //autogenerate `Query` type - result = - // `Query` type for `disallowedFunctionTypeQualifier` query - TQueryC(TFunctionTypesPackageQuery(TDisallowedFunctionTypeQualifierQuery())) - } } diff --git a/rule_packages/c/FunctionTypes.json b/rule_packages/c/FunctionTypes.json index bfa96d09eb..aae4ba8a0f 100644 --- a/rule_packages/c/FunctionTypes.json +++ b/rule_packages/c/FunctionTypes.json @@ -23,19 +23,7 @@ "properties": { "obligation": "required" }, - "queries": [ - { - "description": "The behavior of type qualifiers on a function type is undefined.", - "kind": "problem", - "name": "A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic)", - "precision": "very-high", - "severity": "error", - "short_name": "DisallowedFunctionTypeQualifier", - "tags": [ - "correctness" - ] - } - ], + "queries": [], "title": "A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic)" } } From d49984d0216a62f25e983e70198e6f7b11a50f0e Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Fri, 27 Sep 2024 16:13:42 -0700 Subject: [PATCH 54/62] Format test, commit user README changes. --- ...ionAddressesShouldAddressOperator.expected | 30 +-- c/misra/test/rules/RULE-17-12/test.c | 172 +++++++++--------- docs/user_manual.md | 2 +- 3 files changed, 101 insertions(+), 103 deletions(-) diff --git a/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected index d4862c5978..1a3165a32f 100644 --- a/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected +++ b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected @@ -1,15 +1,15 @@ -| test.c:15:25:15:29 | func2 | The address of function func2 is taken without the & operator. | -| test.c:16:27:16:31 | func3 | The address of function func3 is taken without the & operator. | -| test.c:22:16:22:20 | func1 | The address of function func1 is taken without the & operator. | -| test.c:39:5:39:9 | func1 | The address of function func1 is taken without the & operator. | -| test.c:40:5:40:9 | func2 | The address of function func2 is taken without the & operator. | -| test.c:48:7:48:11 | func1 | The address of function func1 is taken without the & operator. | -| test.c:49:7:49:11 | func2 | The address of function func2 is taken without the & operator. | -| test.c:58:15:58:19 | func1 | The address of function func1 is taken without the & operator. | -| test.c:59:23:59:27 | func2 | The address of function func2 is taken without the & operator. | -| test.c:60:15:60:19 | func1 | The address of function func1 is taken without the & operator. | -| test.c:60:22:60:26 | func2 | The address of function func2 is taken without the & operator. | -| test.c:68:13:68:17 | func1 | The address of function func1 is taken without the & operator. | -| test.c:69:14:69:18 | func1 | The address of function func1 is taken without the & operator. | -| test.c:70:14:70:18 | func1 | The address of function func1 is taken without the & operator. | -| test.c:72:20:72:24 | func1 | The address of function func1 is taken without the & operator. | +| test.c:14:25:14:29 | func2 | The address of function func2 is taken without the & operator. | +| test.c:15:27:15:31 | func3 | The address of function func3 is taken without the & operator. | +| test.c:21:12:21:16 | func1 | The address of function func1 is taken without the & operator. | +| test.c:38:3:38:7 | func1 | The address of function func1 is taken without the & operator. | +| test.c:39:3:39:7 | func2 | The address of function func2 is taken without the & operator. | +| test.c:47:5:47:9 | func1 | The address of function func1 is taken without the & operator. | +| test.c:48:5:48:9 | func2 | The address of function func2 is taken without the & operator. | +| test.c:57:13:57:17 | func1 | The address of function func1 is taken without the & operator. | +| test.c:58:21:58:25 | func2 | The address of function func2 is taken without the & operator. | +| test.c:59:13:59:17 | func1 | The address of function func1 is taken without the & operator. | +| test.c:59:20:59:24 | func2 | The address of function func2 is taken without the & operator. | +| test.c:67:11:67:15 | func1 | The address of function func1 is taken without the & operator. | +| test.c:68:12:68:16 | func1 | The address of function func1 is taken without the & operator. | +| test.c:69:12:69:16 | func1 | The address of function func1 is taken without the & operator. | +| test.c:71:18:71:22 | func1 | The address of function func1 is taken without the & operator. | diff --git a/c/misra/test/rules/RULE-17-12/test.c b/c/misra/test/rules/RULE-17-12/test.c index 4cfe1f6de6..04aaa96af6 100644 --- a/c/misra/test/rules/RULE-17-12/test.c +++ b/c/misra/test/rules/RULE-17-12/test.c @@ -1,30 +1,29 @@ void func1() {} -void func2(int x, char* y) {} +void func2(int x, char *y) {} -typedef struct {} s; +typedef struct { +} s; -int func3() { - return 0; -} +int func3() { return 0; } typedef void (*func_ptr_t1)(); -typedef void (*func_ptr_t2)(int x, char* y); +typedef void (*func_ptr_t2)(int x, char *y); typedef s (*func_ptr_t3)(); -func_ptr_t1 func_ptr1 = &func1; // COMPLIANT -func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT +func_ptr_t1 func_ptr1 = &func1; // COMPLIANT +func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT func_ptr_t3 func_ptr3 = &(func3); // NON-COMPLIANT void take_func(func_ptr_t1 f1, func_ptr_t2 f2); func_ptr_t1 returns_func(int x) { - if (x == 0) { - return func1; // NON-COMPLIANT - } else if (x == 1) { - return &func1; // COMPLIANT - } + if (x == 0) { + return func1; // NON-COMPLIANT + } else if (x == 1) { + return &func1; // COMPLIANT + } - return returns_func(0); // COMPLIANT + return returns_func(0); // COMPLIANT } #define MACRO_IDENTITY(f) (f) @@ -33,77 +32,76 @@ func_ptr_t1 returns_func(int x) { #define MACRO_INVOKE_AND_USE_AS_TOKEN(f) f(0, #f) void test() { - func1(); // COMPLIANT - func2(1, "hello"); // COMPLIANT - - func1; // NON-COMPLIANT - func2; // NON-COMPLIANT - - &func1; // COMPLIANT - &func2; // COMPLIANT - - (func1)(); // COMPLIANT - (func2)(1, "hello"); // COMPLIANT - - &(func1); // NON-COMPLIANT - &(func2); // NON-COMPLIANT - - (&func1)(); // COMPLIANT - (&func2)(1, "hello"); // COMPLIANT - - (func1()); // COMPLIANT - (func2(1, "hello")); // COMPLIANT - - take_func(&func1, &func2); // COMPLIANT - take_func(func1, &func2); // NON-COMPLIANT - take_func(&func1, func2); // NON-COMPLIANT - take_func(func1, func2); // NON-COMPLIANT - - returns_func(0); // COMPLIANT - returns_func(0)(); // COMPLIANT - (returns_func(0))(); // COMPLIANT - - (void*) &func1; // COMPLIANT - (void*) (&func1); // COMPLIANT - (void*) func1; // NON-COMPLIANT - (void*) (func1); // NON-COMPLIANT - ((void*) func1); // NON-COMPLIANT - - MACRO_IDENTITY(func1); // NON-COMPLIANT - MACRO_IDENTITY(func1)(); // NON-COMPLIANT[FALSE NEGATIVE] - MACRO_IDENTITY(&func1); // COMPLIANT - MACRO_IDENTITY(&func1)(); // COMPLIANT - - MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT[FALSE NEGATIVE] - MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT[FALSE NEGATIVE] - MACRO_INVOKE_IMPROVED(&func3); // COMPLIANT - - MACRO_INVOKE_AND_USE_AS_TOKEN(func1); // COMPLIANT - - // Function pointers are exempt from this rule. - func_ptr1(); // COMPLIANT - func_ptr2(1, "hello"); // COMPLIANT - func_ptr1; // COMPLIANT - func_ptr2; // COMPLIANT - &func_ptr1; // COMPLIANT - &func_ptr2; // COMPLIANT - (func_ptr1)(); // COMPLIANT - (func_ptr2)(1, "hello"); // COMPLIANT - (*func_ptr1)(); // COMPLIANT - (*func_ptr2)(1, "hello"); // COMPLIANT - take_func(func_ptr1, func_ptr2); // COMPLIANT - (void*) func_ptr1; // COMPLIANT - (void*) &func_ptr1; // COMPLIANT - (void*) (&func_ptr1); // COMPLIANT - (void*) func_ptr1; // COMPLIANT - (void*) (func_ptr1); // COMPLIANT - ((void*) func_ptr1); // COMPLIANT - MACRO_IDENTITY(func_ptr1); // COMPLIANT - MACRO_IDENTITY(func_ptr1)(); // COMPLIANT - MACRO_IDENTITY(&func_ptr1); // COMPLIANT - (*MACRO_IDENTITY(&func_ptr1))(); // COMPLIANT - MACRO_INVOKE_RISKY(func_ptr3); // COMPLIANT - MACRO_INVOKE_IMPROVED(func_ptr3); // COMPLIANT - MACRO_INVOKE_IMPROVED(*&func_ptr3); // COMPLIANT - + func1(); // COMPLIANT + func2(1, "hello"); // COMPLIANT + + func1; // NON-COMPLIANT + func2; // NON-COMPLIANT + + &func1; // COMPLIANT + &func2; // COMPLIANT + + (func1)(); // COMPLIANT + (func2)(1, "hello"); // COMPLIANT + + &(func1); // NON-COMPLIANT + &(func2); // NON-COMPLIANT + + (&func1)(); // COMPLIANT + (&func2)(1, "hello"); // COMPLIANT + + (func1()); // COMPLIANT + (func2(1, "hello")); // COMPLIANT + + take_func(&func1, &func2); // COMPLIANT + take_func(func1, &func2); // NON-COMPLIANT + take_func(&func1, func2); // NON-COMPLIANT + take_func(func1, func2); // NON-COMPLIANT + + returns_func(0); // COMPLIANT + returns_func(0)(); // COMPLIANT + (returns_func(0))(); // COMPLIANT + + (void *)&func1; // COMPLIANT + (void *)(&func1); // COMPLIANT + (void *)func1; // NON-COMPLIANT + (void *)(func1); // NON-COMPLIANT + ((void *)func1); // NON-COMPLIANT + + MACRO_IDENTITY(func1); // NON-COMPLIANT + MACRO_IDENTITY(func1)(); // NON-COMPLIANT[FALSE NEGATIVE] + MACRO_IDENTITY(&func1); // COMPLIANT + MACRO_IDENTITY (&func1)(); // COMPLIANT + + MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT[FALSE NEGATIVE] + MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT[FALSE NEGATIVE] + MACRO_INVOKE_IMPROVED(&func3); // COMPLIANT + + MACRO_INVOKE_AND_USE_AS_TOKEN(func1); // COMPLIANT + + // Function pointers are exempt from this rule. + func_ptr1(); // COMPLIANT + func_ptr2(1, "hello"); // COMPLIANT + func_ptr1; // COMPLIANT + func_ptr2; // COMPLIANT + &func_ptr1; // COMPLIANT + &func_ptr2; // COMPLIANT + (func_ptr1)(); // COMPLIANT + (func_ptr2)(1, "hello"); // COMPLIANT + (*func_ptr1)(); // COMPLIANT + (*func_ptr2)(1, "hello"); // COMPLIANT + take_func(func_ptr1, func_ptr2); // COMPLIANT + (void *)func_ptr1; // COMPLIANT + (void *)&func_ptr1; // COMPLIANT + (void *)(&func_ptr1); // COMPLIANT + (void *)func_ptr1; // COMPLIANT + (void *)(func_ptr1); // COMPLIANT + ((void *)func_ptr1); // COMPLIANT + MACRO_IDENTITY(func_ptr1); // COMPLIANT + MACRO_IDENTITY(func_ptr1)(); // COMPLIANT + MACRO_IDENTITY(&func_ptr1); // COMPLIANT + (*MACRO_IDENTITY(&func_ptr1))(); // COMPLIANT + MACRO_INVOKE_RISKY(func_ptr3); // COMPLIANT + MACRO_INVOKE_IMPROVED(func_ptr3); // COMPLIANT + MACRO_INVOKE_IMPROVED(*&func_ptr3); // COMPLIANT } \ No newline at end of file diff --git a/docs/user_manual.md b/docs/user_manual.md index 5799d73e6f..db0f836339 100644 --- a/docs/user_manual.md +++ b/docs/user_manual.md @@ -78,7 +78,7 @@ The datasheet _"CodeQL Coding Standards: supported rules"_, provided with each r [^1]: AUTOSAR C++ versions R22-11, R21-11, R20-11, R19-11 and R19-03 are all identical as indicated in the document change history. [^2]: The unimplemented supportable AUTOSAR rules are `A7-1-8` and `A8-2-1`. These rules require additional support in the CodeQL CLI to ensure the required information is available in the CodeQL database to identify violations of these rules. -[^3]: The unimplemented supportable MISRA C 2012 rules are `Rule 9.5` and `Dir 4.14`. `Rule 9.5` requires additional support in the CodeQL CLI to ensure the required information is available in the CodeQL database to identify violations of these rules. `Dir 4.14` is covered by the default CodeQL queries, which identify potential security vulnerabilities caused by not validating external input. +[^3]: The unimplemented supportable MISRA C 2012 rules are `Rule 9.5`, `Rule 17.13`, and `Dir 4.14`. `Rule 9.5` and `Rule 17.13` require additional support in the CodeQL CLI to ensure the required information is available in the CodeQL database to identify violations of these rules. `Dir 4.14` is covered by the default CodeQL queries, which identify potential security vulnerabilities caused by not validating external input. [^4]: The rules 5.13.7, 19.0.1 and 19.1.2 are not planned to be implemented by CodeQL as they are compiler checked in all supported compilers. ## Supported environment From a8d832b0606b46a5dd05bc22558b95ebbc7c0df7 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Sat, 28 Sep 2024 11:24:01 -0700 Subject: [PATCH 55/62] Add defense against cpp code based on MRVA results. Add comments. --- .../FunctionAddressesShouldAddressOperator.ql | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql index 96c466150b..824e873e28 100644 --- a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql +++ b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql @@ -15,8 +15,18 @@ import cpp import codingstandards.c.misra predicate isImplicitlyAddressed(FunctionAccess access) { - not access.getParent() instanceof AddressOfExpr or - exists(ParenthesisExpr parens | parens.getExpr() = access) + ( + not access.getParent() instanceof AddressOfExpr + or + // This catches "&(foo)", which could be considered to be somewhat less + // readable than "(&foo)". + exists(ParenthesisExpr parens | parens.getExpr() = access) + ) and + // Note: the following *seems* to only exist in c++ codebases, for instance, + // when calling a member. In c, this syntax should always extract as a + // [FunctionCall] rather than a [ExprCall] of a [FunctionAccess]. Still, this + // is a good pattern to be defensive against. + not exists(ExprCall call | call.getExpr() = access) } from FunctionAccess funcAccess From 1007a5324883e41523ff7e4bd6e20024c4f151a4 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Fri, 4 Oct 2024 09:38:41 -0700 Subject: [PATCH 56/62] Allow `&(f)` under rule 17-12 --- .../FunctionAddressesShouldAddressOperator.ql | 8 +------- .../FunctionAddressesShouldAddressOperator.expected | 4 +--- c/misra/test/rules/RULE-17-12/test.c | 10 +++++----- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql index 824e873e28..30d86b0447 100644 --- a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql +++ b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql @@ -15,13 +15,7 @@ import cpp import codingstandards.c.misra predicate isImplicitlyAddressed(FunctionAccess access) { - ( - not access.getParent() instanceof AddressOfExpr - or - // This catches "&(foo)", which could be considered to be somewhat less - // readable than "(&foo)". - exists(ParenthesisExpr parens | parens.getExpr() = access) - ) and + not access.getParent() instanceof AddressOfExpr and // Note: the following *seems* to only exist in c++ codebases, for instance, // when calling a member. In c, this syntax should always extract as a // [FunctionCall] rather than a [ExprCall] of a [FunctionAccess]. Still, this diff --git a/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected index 1a3165a32f..5a37cbd97e 100644 --- a/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected +++ b/c/misra/test/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.expected @@ -1,10 +1,8 @@ | test.c:14:25:14:29 | func2 | The address of function func2 is taken without the & operator. | -| test.c:15:27:15:31 | func3 | The address of function func3 is taken without the & operator. | +| test.c:15:25:15:29 | func3 | The address of function func3 is taken without the & operator. | | test.c:21:12:21:16 | func1 | The address of function func1 is taken without the & operator. | | test.c:38:3:38:7 | func1 | The address of function func1 is taken without the & operator. | | test.c:39:3:39:7 | func2 | The address of function func2 is taken without the & operator. | -| test.c:47:5:47:9 | func1 | The address of function func1 is taken without the & operator. | -| test.c:48:5:48:9 | func2 | The address of function func2 is taken without the & operator. | | test.c:57:13:57:17 | func1 | The address of function func1 is taken without the & operator. | | test.c:58:21:58:25 | func2 | The address of function func2 is taken without the & operator. | | test.c:59:13:59:17 | func1 | The address of function func1 is taken without the & operator. | diff --git a/c/misra/test/rules/RULE-17-12/test.c b/c/misra/test/rules/RULE-17-12/test.c index 04aaa96af6..5ab5a4984d 100644 --- a/c/misra/test/rules/RULE-17-12/test.c +++ b/c/misra/test/rules/RULE-17-12/test.c @@ -10,9 +10,9 @@ typedef void (*func_ptr_t1)(); typedef void (*func_ptr_t2)(int x, char *y); typedef s (*func_ptr_t3)(); -func_ptr_t1 func_ptr1 = &func1; // COMPLIANT -func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT -func_ptr_t3 func_ptr3 = &(func3); // NON-COMPLIANT +func_ptr_t1 func_ptr1 = &func1; // COMPLIANT +func_ptr_t2 func_ptr2 = func2; // NON-COMPLIANT +func_ptr_t3 func_ptr3 = func3 + 0; // NON-COMPLIANT void take_func(func_ptr_t1 f1, func_ptr_t2 f2); @@ -44,8 +44,8 @@ void test() { (func1)(); // COMPLIANT (func2)(1, "hello"); // COMPLIANT - &(func1); // NON-COMPLIANT - &(func2); // NON-COMPLIANT + &(func1); // COMPLIANT + &(func2); // COMPLIANT (&func1)(); // COMPLIANT (&func2)(1, "hello"); // COMPLIANT From c972403d1a2f39874d66a355cc69cdbb6d5cd523 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Fri, 4 Oct 2024 11:35:49 -0700 Subject: [PATCH 57/62] Tag as amendment3, mark 17-13 not supportable --- .../FunctionAddressesShouldAddressOperator.ql | 1 + rule_packages/c/FunctionTypes.json | 10 ++-------- rules.csv | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql index 30d86b0447..c95612b7ba 100644 --- a/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql +++ b/c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql @@ -8,6 +8,7 @@ * @problem.severity error * @tags external/misra/id/rule-17-12 * readability + * external/misra/c/2012/amendment3 * external/misra/obligation/advisory */ diff --git a/rule_packages/c/FunctionTypes.json b/rule_packages/c/FunctionTypes.json index aae4ba8a0f..d9d8b6496d 100644 --- a/rule_packages/c/FunctionTypes.json +++ b/rule_packages/c/FunctionTypes.json @@ -13,18 +13,12 @@ "severity": "error", "short_name": "FunctionAddressesShouldAddressOperator", "tags": [ - "readability" + "readability", + "external/misra/c/2012/amendment3" ] } ], "title": "A function identifier should only be called with a parenthesized parameter list or used with a & (address-of)" - }, - "RULE-17-13": { - "properties": { - "obligation": "required" - }, - "queries": [], - "title": "A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic)" } } } \ No newline at end of file diff --git a/rules.csv b/rules.csv index b5e15ba6f6..475ea1d66c 100644 --- a/rules.csv +++ b/rules.csv @@ -739,7 +739,7 @@ c,MISRA-C-2012,RULE-17-9,Yes,Mandatory,,,Verify that a function declared with _N c,MISRA-C-2012,RULE-17-10,Yes,Required,,,A function declared with _noreturn shall have a return type of void,,NoReturn,Easy, c,MISRA-C-2012,RULE-17-11,Yes,Advisory,,,A function without a branch that returns shall be declared with _Noreturn,,NoReturn,Easy, c,MISRA-C-2012,RULE-17-12,Yes,Advisory,,,A function identifier should only be called with a parenthesized parameter list or used with a & (address-of),,FunctionTypes,Easy, -c,MISRA-C-2012,RULE-17-13,Yes,Required,,,"A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic)",,FunctionTypes,Easy, +c,MISRA-C-2012,RULE-17-13,No,Required,,,"A function type shall not include any type qualifiers (const, volatile, restrict, or _Atomic)",,,Easy, c,MISRA-C-2012,RULE-18-1,Yes,Required,,,A pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operand,M5-0-16,Pointers1,Import, c,MISRA-C-2012,RULE-18-2,Yes,Required,,,Subtraction between pointers shall only be applied to pointers that address elements of the same array,M5-0-17,Pointers1,Import, c,MISRA-C-2012,RULE-18-3,Yes,Required,,,"The relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same object",M5-0-18,Pointers1,Import, From c9a7b05a886028d36521b01e3db63b4766045f89 Mon Sep 17 00:00:00 2001 From: lcartey <5377966+lcartey@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:18:22 +0000 Subject: [PATCH 58/62] Upgrading `github/codeql` dependency to 2.15.5 --- c/cert/src/codeql-pack.lock.yml | 12 ++++++++---- c/cert/src/qlpack.yml | 2 +- c/cert/test/codeql-pack.lock.yml | 12 ++++++++---- c/common/src/codeql-pack.lock.yml | 12 ++++++++---- c/common/src/qlpack.yml | 2 +- c/common/test/codeql-pack.lock.yml | 12 ++++++++---- c/misra/src/codeql-pack.lock.yml | 12 ++++++++---- c/misra/src/qlpack.yml | 2 +- c/misra/test/codeql-pack.lock.yml | 12 ++++++++---- cpp/autosar/src/codeql-pack.lock.yml | 12 ++++++++---- cpp/autosar/src/qlpack.yml | 2 +- cpp/autosar/test/codeql-pack.lock.yml | 12 ++++++++---- cpp/cert/src/codeql-pack.lock.yml | 12 ++++++++---- cpp/cert/src/qlpack.yml | 2 +- cpp/cert/test/codeql-pack.lock.yml | 12 ++++++++---- cpp/common/src/codeql-pack.lock.yml | 12 ++++++++---- cpp/common/src/qlpack.yml | 4 ++-- cpp/common/test/codeql-pack.lock.yml | 12 ++++++++---- cpp/misra/src/codeql-pack.lock.yml | 12 ++++++++---- cpp/misra/src/qlpack.yml | 2 +- cpp/misra/test/codeql-pack.lock.yml | 12 ++++++++---- cpp/report/src/codeql-pack.lock.yml | 12 ++++++++---- cpp/report/src/qlpack.yml | 2 +- .../generate_modules/queries/codeql-pack.lock.yml | 12 ++++++++---- scripts/generate_modules/queries/qlpack.yml | 2 +- supported_codeql_configs.json | 6 +++--- 26 files changed, 141 insertions(+), 77 deletions(-) diff --git a/c/cert/src/codeql-pack.lock.yml b/c/cert/src/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/c/cert/src/codeql-pack.lock.yml +++ b/c/cert/src/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/c/cert/src/qlpack.yml b/c/cert/src/qlpack.yml index a0adb282a4..f0daa6334a 100644 --- a/c/cert/src/qlpack.yml +++ b/c/cert/src/qlpack.yml @@ -5,4 +5,4 @@ suites: codeql-suites license: MIT dependencies: codeql/common-c-coding-standards: '*' - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 diff --git a/c/cert/test/codeql-pack.lock.yml b/c/cert/test/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/c/cert/test/codeql-pack.lock.yml +++ b/c/cert/test/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/c/common/src/codeql-pack.lock.yml b/c/common/src/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/c/common/src/codeql-pack.lock.yml +++ b/c/common/src/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/c/common/src/qlpack.yml b/c/common/src/qlpack.yml index b1571ec4ec..5f18365483 100644 --- a/c/common/src/qlpack.yml +++ b/c/common/src/qlpack.yml @@ -3,4 +3,4 @@ version: 2.36.0-dev license: MIT dependencies: codeql/common-cpp-coding-standards: '*' - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 diff --git a/c/common/test/codeql-pack.lock.yml b/c/common/test/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/c/common/test/codeql-pack.lock.yml +++ b/c/common/test/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/c/misra/src/codeql-pack.lock.yml b/c/misra/src/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/c/misra/src/codeql-pack.lock.yml +++ b/c/misra/src/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/c/misra/src/qlpack.yml b/c/misra/src/qlpack.yml index 5de8472821..9d0ed62e06 100644 --- a/c/misra/src/qlpack.yml +++ b/c/misra/src/qlpack.yml @@ -6,4 +6,4 @@ license: MIT default-suite-file: codeql-suites/misra-c-default.qls dependencies: codeql/common-c-coding-standards: '*' - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 diff --git a/c/misra/test/codeql-pack.lock.yml b/c/misra/test/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/c/misra/test/codeql-pack.lock.yml +++ b/c/misra/test/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/autosar/src/codeql-pack.lock.yml b/cpp/autosar/src/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/autosar/src/codeql-pack.lock.yml +++ b/cpp/autosar/src/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/autosar/src/qlpack.yml b/cpp/autosar/src/qlpack.yml index 947013155f..93a0f4bd9a 100644 --- a/cpp/autosar/src/qlpack.yml +++ b/cpp/autosar/src/qlpack.yml @@ -5,4 +5,4 @@ suites: codeql-suites license: MIT dependencies: codeql/common-cpp-coding-standards: '*' - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 diff --git a/cpp/autosar/test/codeql-pack.lock.yml b/cpp/autosar/test/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/autosar/test/codeql-pack.lock.yml +++ b/cpp/autosar/test/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/cert/src/codeql-pack.lock.yml b/cpp/cert/src/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/cert/src/codeql-pack.lock.yml +++ b/cpp/cert/src/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/cert/src/qlpack.yml b/cpp/cert/src/qlpack.yml index 3a435b5e8e..3a85e2aa20 100644 --- a/cpp/cert/src/qlpack.yml +++ b/cpp/cert/src/qlpack.yml @@ -4,5 +4,5 @@ description: CERT C++ 2016 suites: codeql-suites license: MIT dependencies: - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 codeql/common-cpp-coding-standards: '*' diff --git a/cpp/cert/test/codeql-pack.lock.yml b/cpp/cert/test/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/cert/test/codeql-pack.lock.yml +++ b/cpp/cert/test/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/common/src/codeql-pack.lock.yml b/cpp/common/src/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/common/src/codeql-pack.lock.yml +++ b/cpp/common/src/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/common/src/qlpack.yml b/cpp/common/src/qlpack.yml index a2448fd608..b7f90b4cd3 100644 --- a/cpp/common/src/qlpack.yml +++ b/cpp/common/src/qlpack.yml @@ -2,6 +2,6 @@ name: codeql/common-cpp-coding-standards version: 2.36.0-dev license: MIT dependencies: - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 dataExtensions: - - ext/*.model.yml \ No newline at end of file +- ext/*.model.yml diff --git a/cpp/common/test/codeql-pack.lock.yml b/cpp/common/test/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/common/test/codeql-pack.lock.yml +++ b/cpp/common/test/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/misra/src/codeql-pack.lock.yml b/cpp/misra/src/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/misra/src/codeql-pack.lock.yml +++ b/cpp/misra/src/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/misra/src/qlpack.yml b/cpp/misra/src/qlpack.yml index 4c0aa45f4f..b713614f68 100644 --- a/cpp/misra/src/qlpack.yml +++ b/cpp/misra/src/qlpack.yml @@ -5,4 +5,4 @@ default-suite: codeql-suites/misra-cpp-default.qls license: MIT dependencies: codeql/common-cpp-coding-standards: '*' - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 diff --git a/cpp/misra/test/codeql-pack.lock.yml b/cpp/misra/test/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/misra/test/codeql-pack.lock.yml +++ b/cpp/misra/test/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/report/src/codeql-pack.lock.yml b/cpp/report/src/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/cpp/report/src/codeql-pack.lock.yml +++ b/cpp/report/src/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/cpp/report/src/qlpack.yml b/cpp/report/src/qlpack.yml index 81f95392c9..f90669908d 100644 --- a/cpp/report/src/qlpack.yml +++ b/cpp/report/src/qlpack.yml @@ -2,4 +2,4 @@ name: codeql/report-cpp-coding-standards version: 2.36.0-dev license: MIT dependencies: - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 diff --git a/scripts/generate_modules/queries/codeql-pack.lock.yml b/scripts/generate_modules/queries/codeql-pack.lock.yml index 514e6963d0..4edf97c6f8 100644 --- a/scripts/generate_modules/queries/codeql-pack.lock.yml +++ b/scripts/generate_modules/queries/codeql-pack.lock.yml @@ -2,13 +2,17 @@ lockVersion: 1.0.0 dependencies: codeql/cpp-all: - version: 0.9.3 + version: 0.12.2 codeql/dataflow: + version: 0.1.5 + codeql/rangeanalysis: version: 0.0.4 codeql/ssa: - version: 0.1.5 + version: 0.2.5 codeql/tutorial: - version: 0.1.5 + version: 0.2.5 + codeql/typetracking: + version: 0.2.5 codeql/util: - version: 0.1.5 + version: 0.2.5 compiled: false diff --git a/scripts/generate_modules/queries/qlpack.yml b/scripts/generate_modules/queries/qlpack.yml index 4f3768cd79..4ab2483c04 100644 --- a/scripts/generate_modules/queries/qlpack.yml +++ b/scripts/generate_modules/queries/qlpack.yml @@ -2,4 +2,4 @@ name: codeql/standard-library-extraction-cpp-coding-standards version: 0.0.0 license: MIT dependencies: - codeql/cpp-all: 0.9.3 + codeql/cpp-all: 0.12.2 diff --git a/supported_codeql_configs.json b/supported_codeql_configs.json index 227f41babd..a97c7d83d2 100644 --- a/supported_codeql_configs.json +++ b/supported_codeql_configs.json @@ -1,9 +1,9 @@ { "supported_environment": [ { - "codeql_cli": "2.14.6", - "codeql_standard_library": "codeql-cli/v2.14.6", - "codeql_cli_bundle": "codeql-bundle-v2.14.6" + "codeql_cli": "2.15.5", + "codeql_standard_library": "codeql-cli/v2.15.5", + "codeql_cli_bundle": "codeql-bundle-v2.15.5" } ], "supported_language": [ From c7d3c73855de9b5f71e3fb09bda4c0356ba11eca Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 4 Oct 2024 23:31:26 +0100 Subject: [PATCH 59/62] Fix query formatting issue In CodeQL CLI 2.15.5 it formats this line together. --- .../rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql b/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql index 2b435de94e..10b24b8c8a 100644 --- a/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql +++ b/c/misra/src/rules/RULE-10-1/OperandsOfAnInappropriateEssentialType.ql @@ -178,8 +178,7 @@ predicate isInappropriateEssentialType( child = [ operator.(BinaryBitwiseOperation).getAnOperand(), - operator.(AssignBitwiseOperation).getAnOperand(), - operator.(ComplementExpr).getAnOperand() + operator.(AssignBitwiseOperation).getAnOperand(), operator.(ComplementExpr).getAnOperand() ] and not operator instanceof LShiftExpr and not operator instanceof RShiftExpr and From b3ca674febc91551b08656e02985685701b38305 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Mon, 7 Oct 2024 10:19:42 +0100 Subject: [PATCH 60/62] Switch to workflow dispatch for cross repo testing The PR testing jobs were still using repository dispatch, but the target workflows had changed to use workflow dispatch. --- .github/workflows/dispatch-matrix-check.yml | 50 ------------------- .../dispatch-matrix-test-on-comment.yml | 19 ++++--- .../dispatch-release-performance-check.yml | 19 ++++--- 3 files changed, 24 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/dispatch-matrix-check.yml diff --git a/.github/workflows/dispatch-matrix-check.yml b/.github/workflows/dispatch-matrix-check.yml deleted file mode 100644 index 845a8fc4ae..0000000000 --- a/.github/workflows/dispatch-matrix-check.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: 🤖 Run Matrix Check - -on: - pull_request_target: - types: [synchronize, opened] - branches: - - "matrix/**" - workflow_dispatch: - -jobs: - dispatch-matrix-check: - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Check permission - id: check-write-permission - uses: ./.github/actions/check-permissions - with: - minimum-permission: "write" - - - name: Generate token - id: generate-token - uses: actions/create-github-app-token@v1 - with: - app-id: ${{ vars.AUTOMATION_APP_ID }} - private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }} - owner: ${{ github.repository_owner }} - repositories: "codeql-coding-standards-release-engineering" - - - name: Dispatch Matrix Testing Job - if: steps.check-write-permission.outputs.has-permission - uses: peter-evans/repository-dispatch@v2 - with: - token: ${{ steps.generate-token.outputs.token }} - repository: github/codeql-coding-standards-release-engineering - event-type: matrix-test - client-payload: '{"pr": "${{ github.event.number }}"}' - - - uses: actions/github-script@v6 - if: steps.check-write-permission.outputs.has-permission - with: - script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: '🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results.

:bulb: If you do not hear back from me please check my status! **I will report even if this PR does not contain files eligible for matrix testing.**' - }) diff --git a/.github/workflows/dispatch-matrix-test-on-comment.yml b/.github/workflows/dispatch-matrix-test-on-comment.yml index 4f9f9a5b1e..297b6fbc7e 100644 --- a/.github/workflows/dispatch-matrix-test-on-comment.yml +++ b/.github/workflows/dispatch-matrix-test-on-comment.yml @@ -26,14 +26,19 @@ jobs: owner: ${{ github.repository_owner }} repositories: "codeql-coding-standards-release-engineering" - - name: Dispatch Matrix Testing Job + - name: Invoke matrix testing job if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') && steps.check-write-permission.outputs.has-permission }} - uses: peter-evans/repository-dispatch@v2 - with: - token: ${{ steps.generate-token.outputs.token }} - repository: github/codeql-coding-standards-release-engineering - event-type: matrix-test - client-payload: '{"pr": "${{ github.event.issue.number }}"}' + env: + ISSUE_NR: ${{ github.event.issue.number }} + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + run: | + jq -n \ + --arg issue_nr "$ISSUE_NR" \ + '{"issue-nr": $issue_nr}' \ + | \ + gh workflow run pr-compiler-validation.yml \ + --json \ + -R github/codeql-coding-standards-release-engineering - uses: actions/github-script@v6 if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') && steps.check-write-permission.outputs.has-permission }} diff --git a/.github/workflows/dispatch-release-performance-check.yml b/.github/workflows/dispatch-release-performance-check.yml index 7e28a9c4f9..260846185a 100644 --- a/.github/workflows/dispatch-release-performance-check.yml +++ b/.github/workflows/dispatch-release-performance-check.yml @@ -26,14 +26,19 @@ jobs: owner: ${{ github.repository_owner }} repositories: "codeql-coding-standards-release-engineering" - - name: Dispatch Performance Testing Job + - name: Invoke performance test if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') && steps.check-write-permission.outputs.has-permission }} - uses: peter-evans/repository-dispatch@v2 - with: - token: ${{ steps.generate-token.outputs.token }} - repository: github/codeql-coding-standards-release-engineering - event-type: performance-test - client-payload: '{"pr": "${{ github.event.issue.number }}"}' + env: + ISSUE_NR: ${{ github.event.issue.number }} + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + run: | + jq -n \ + --arg issue_nr "$ISSUE_NR" \ + '{"issue-nr": $issue_nr}' \ + | \ + gh workflow run pr-performance-testing.yml \ + --json \ + -R github/codeql-coding-standards-release-engineering - uses: actions/github-script@v6 if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') && steps.check-write-permission.outputs.has-permission }} From 4c17999deb60b01c81f82a704665eee2ddbcf4fd Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Mon, 7 Oct 2024 14:00:23 +0100 Subject: [PATCH 61/62] MEM53-CPP: Remove FP introduced by upgrade to 2.15.5 Flow through realloc was added in the standard library, so move to barrier instead of node filter --- cpp/cert/src/rules/MEM53-CPP/ManuallyManagedLifetime.qll | 9 ++++++--- ...ssingConstructorCallForManuallyManagedObject.expected | 4 ---- cpp/cert/test/rules/MEM53-CPP/test.cpp | 5 ++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cpp/cert/src/rules/MEM53-CPP/ManuallyManagedLifetime.qll b/cpp/cert/src/rules/MEM53-CPP/ManuallyManagedLifetime.qll index 358a3583fc..54fafc60d7 100644 --- a/cpp/cert/src/rules/MEM53-CPP/ManuallyManagedLifetime.qll +++ b/cpp/cert/src/rules/MEM53-CPP/ManuallyManagedLifetime.qll @@ -14,12 +14,15 @@ module AllocToStaticCastConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node source) { exists(AllocationExpr ae | ae.getType().getUnspecifiedType() instanceof VoidPointerType and - source.asExpr() = ae and - // Ignore realloc, as that memory may already be partially constructed - not ae.(FunctionCall).getTarget().getName().toLowerCase().matches("%realloc%") + source.asExpr() = ae ) } + predicate isBarrier(DataFlow::Node sanitizer) { + // Ignore realloc, as that memory may already be partially constructed + sanitizer.asExpr().(FunctionCall).getTarget().getName().toLowerCase().matches("%realloc%") + } + predicate isSink(DataFlow::Node sink) { exists(StaticOrCStyleCast sc, Class nonTrivialClass | sc.getExpr() = sink.asExpr() and diff --git a/cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected b/cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected index e64315e044..12dcb2d8ff 100644 --- a/cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected +++ b/cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected @@ -1,5 +1,4 @@ edges -| test.cpp:65:21:65:34 | call to operator new | test.cpp:67:26:67:32 | call to realloc | nodes | test.cpp:16:26:16:31 | call to malloc | semmle.label | call to malloc | | test.cpp:17:38:17:43 | call to malloc | semmle.label | call to malloc | @@ -10,8 +9,6 @@ nodes | test.cpp:47:26:47:39 | call to operator new | semmle.label | call to operator new | | test.cpp:49:29:49:42 | call to operator new | semmle.label | call to operator new | | test.cpp:51:29:51:42 | call to operator new | semmle.label | call to operator new | -| test.cpp:65:21:65:34 | call to operator new | semmle.label | call to operator new | -| test.cpp:67:26:67:32 | call to realloc | semmle.label | call to realloc | subpaths #select | test.cpp:16:26:16:31 | call to malloc | test.cpp:16:26:16:31 | call to malloc | test.cpp:16:26:16:31 | call to malloc | Allocation to cast without constructor call | @@ -23,4 +20,3 @@ subpaths | test.cpp:47:26:47:39 | call to operator new | test.cpp:47:26:47:39 | call to operator new | test.cpp:47:26:47:39 | call to operator new | Allocation to cast without constructor call | | test.cpp:49:29:49:42 | call to operator new | test.cpp:49:29:49:42 | call to operator new | test.cpp:49:29:49:42 | call to operator new | Allocation to cast without constructor call | | test.cpp:51:29:51:42 | call to operator new | test.cpp:51:29:51:42 | call to operator new | test.cpp:51:29:51:42 | call to operator new | Allocation to cast without constructor call | -| test.cpp:67:26:67:32 | call to realloc | test.cpp:65:21:65:34 | call to operator new | test.cpp:67:26:67:32 | call to realloc | Allocation to cast without constructor call | diff --git a/cpp/cert/test/rules/MEM53-CPP/test.cpp b/cpp/cert/test/rules/MEM53-CPP/test.cpp index 82c0953a60..12c6d1ee56 100644 --- a/cpp/cert/test/rules/MEM53-CPP/test.cpp +++ b/cpp/cert/test/rules/MEM53-CPP/test.cpp @@ -63,7 +63,6 @@ void test_no_constructor_but_has_destructor() { void test_realloc() { void *goodAlloc = ::operator new(sizeof(ClassA)); - ClassA *a1 = new (goodAlloc) ClassA{1}; // COMPLIANT - ClassA *a2 = (ClassA *)realloc( - goodAlloc, sizeof(ClassA) * 2); // COMPLIANT [FALSE_POSITIVE] + ClassA *a1 = new (goodAlloc) ClassA{1}; // COMPLIANT + ClassA *a2 = (ClassA *)realloc(goodAlloc, sizeof(ClassA) * 2); // COMPLIANT } \ No newline at end of file From 12b1c4ee138fcbb56d35247702f0049f6d913c16 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Mon, 7 Oct 2024 14:03:05 +0100 Subject: [PATCH 62/62] Add change note --- change_notes/2024-10-07-upgrade-to-2.15.5.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 change_notes/2024-10-07-upgrade-to-2.15.5.md diff --git a/change_notes/2024-10-07-upgrade-to-2.15.5.md b/change_notes/2024-10-07-upgrade-to-2.15.5.md new file mode 100644 index 0000000000..d3d4151e78 --- /dev/null +++ b/change_notes/2024-10-07-upgrade-to-2.15.5.md @@ -0,0 +1 @@ +- Updated the CodeQL version to `2.15.5`. \ No newline at end of file