Skip to content

Commit 608fc82

Browse files
authored
Merge branch 'main' into lcartey/fix-range-based-for-loops
2 parents 38a5ea6 + 23e25b9 commit 608fc82

File tree

141 files changed

+1150
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+1150
-288
lines changed

README.md

Lines changed: 2 additions & 2 deletions

c/cert/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT

c/cert/src/rules/INT34-C/ExprShiftedbyNegativeOrGreaterPrecisionOperand.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import cpp
1414
import codingstandards.c.cert
1515
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
16-
import semmle.code.cpp.ir.internal.ASTValueNumbering
16+
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
1717
import semmle.code.cpp.controlflow.Guards
1818

1919
/*

c/cert/src/rules/STR31-C/StringsHasSufficientSpaceForTheNullTerminator.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import cpp
1717
import codingstandards.c.cert
1818
import semmle.code.cpp.dataflow.TaintTracking
19-
import semmle.code.cpp.dataflow.internal.TaintTrackingUtil
2019
import codingstandards.cpp.PossiblyUnsafeStringOperation
2120

2221
/**

c/cert/src/rules/STR32-C/NonNullTerminatedToFunctionThatExpectsAString.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import cpp
1616
import codingstandards.c.cert
1717
import codingstandards.cpp.Naming
1818
import semmle.code.cpp.dataflow.TaintTracking
19-
import semmle.code.cpp.dataflow.internal.TaintTrackingUtil
2019
import codingstandards.cpp.PossiblyUnsafeStringOperation
2120

2221
/**

c/cert/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards-tests
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

c/common/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
license: MIT
44
dependencies:
55
codeql/common-cpp-coding-standards: '*'

c/common/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards-tests
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

c/misra/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-c-coding-standards
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
description: MISRA C 2012
44
suites: codeql-suites
55
license: MIT

c/misra/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-c-coding-standards-tests
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:
Lines changed: 1 addition & 0 deletions
Lines changed: 3 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Lines changed: 18 additions & 0 deletions

cpp/autosar/src/codeql-suites/autosar-advisory.qls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- description: AUTOSAR C++14 Guidelines 20-11 (Advisory)
1+
- description: AUTOSAR C++14 Guidelines R22-11, R21-11, R20-11, R19-11 and R19-03 (Advisory)
22
- qlpack: codeql/autosar-cpp-coding-standards
33
- include:
44
kind:

cpp/autosar/src/codeql-suites/autosar-audit.qls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- description: AUTOSAR C++14 Guidelines 20-11 (Audit)
1+
- description: AUTOSAR C++14 Guidelines R22-11, R21-11, R20-11, R19-11 and R19-03 (Audit)
22
- qlpack: codeql/autosar-cpp-coding-standards
33
- include:
44
kind:

cpp/autosar/src/codeql-suites/autosar-default.qls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- description: AUTOSAR C++14 Guidelines 20-11 (Default)
1+
- description: AUTOSAR C++14 Guidelines R22-11, R21-11, R20-11, R19-11 and R19-03 (Default)
22
- qlpack: codeql/autosar-cpp-coding-standards
33
- include:
44
kind:

cpp/autosar/src/codeql-suites/autosar-required.qls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- description: AUTOSAR C++14 Guidelines 20-11 (Required)
1+
- description: AUTOSAR C++14 Guidelines R22-11, R21-11, R20-11, R19-11 and R19-03 (Required)
22
- qlpack: codeql/autosar-cpp-coding-standards
33
- include:
44
kind:

cpp/autosar/src/codeql-suites/autosar-single-translation-unit.qls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- description: AUTOSAR C++14 Guidelines 20-11 (Single Translation Unit)
1+
- description: AUTOSAR C++14 Guidelines R22-11, R21-11, R20-11, R19-11 and R19-03 (Single Translation Unit)
22
- qlpack: codeql/autosar-cpp-coding-standards
33
- include:
44
kind:

cpp/autosar/src/qlpack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: codeql/autosar-cpp-coding-standards
2-
version: 2.18.0-dev
3-
description: AUTOSAR C++14 Guidelines 20-11
2+
version: 2.19.0-dev
3+
description: AUTOSAR C++14 Guidelines R22-11, R21-11, R20-11, R19-11 and R19-03
44
suites: codeql-suites
55
license: MIT
66
dependencies:

cpp/autosar/src/rules/A0-4-1/FloatingPointImplementationShallComplyWithIeeeStandard.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import codingstandards.cpp.autosar
2121
import codingstandards.cpp.TypeUses
2222

2323
class NumericLimits extends Class {
24-
NumericLimits() { this.hasQualifiedName("std", "numeric_limits") }
24+
NumericLimits() { this.hasQualifiedName("std", ["numeric_limits", "__libcpp_numeric_limits"]) }
2525

2626
/**
2727
* Gets the template argument specified for this type.

cpp/autosar/src/rules/A0-4-3/CompilerImplementationShallComplyWithCPP14Standard.ql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ from File f, string flag
2020
where
2121
not isExcluded(f, ToolchainPackage::compilerImplementationShallComplyWithCPP14StandardQuery()) and
2222
exists(Compilation c | f = c.getAFileCompiled() |
23-
c.getAnArgument() = flag and flag.regexpMatch("-std=(?!c\\+\\+14)[\\w+]+")
24-
)
23+
flag =
24+
max(string std, int index |
25+
c.getArgument(index) = std and std.matches("-std=%")
26+
|
27+
std order by index
28+
)
29+
) and
30+
flag != "-std=c++14"
2531
select f,
2632
"File '" + f.getBaseName() + "' compiled with flag '" + flag +
2733
"' which does not strictly comply with ISO C++14."

cpp/autosar/src/rules/A1-1-1/StrstreamTypesAreDeprecated.ql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
import cpp
1616
import codingstandards.cpp.autosar
17-
import codingstandards.cpp.TypeUses
1817

19-
from Class c, Locatable l
18+
from TypeMention l, Class c
2019
where
2120
not isExcluded(l, ToolchainPackage::strstreamTypesAreDeprecatedQuery()) and
2221
c.hasQualifiedName("std", ["strstreambuf", "ostrstream", "istrstream"]) and
23-
exists(Type t | t = c | l = getATypeUse(t))
24-
select l, "Use of <strstream> class '" + c.getQualifiedName() + "' is deprecated."
22+
l.getMentionedType() = c
23+
select l, "Use of <strstream> class '" + c.getName() + "' is deprecated."

cpp/autosar/src/rules/A1-1-3/UncompliantOptimizationOptionMustBeDisabledInCompiler.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ where
2626
c.getAnArgument() = flag and
2727
flag =
2828
[
29-
"-Ofast", "-ffast-math", "-fgnu-keywords", "-fno-signed-zeroes", "-fno-signed-zeros", "-menable-unsafe-fp-math",
29+
"-Ofast", "-ffast-math", "-fgnu-keywords", "-fno-signed-zeros", "-menable-unsafe-fp-math",
3030
"-menable-no-nans", "-menable-no-infs", "-menable-unsafe-fp-math", "-ffinite-math-only",
3131
"-ffloat-store"
3232
]

cpp/autosar/src/rules/A15-3-3/MissingCatchHandlerInMain.ql

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,6 @@ import codingstandards.cpp.exceptions.ThirdPartyExceptions
2222
import codingstandards.cpp.standardlibrary.Exceptions
2323
import codingstandards.cpp.EncapsulatingFunctions
2424

25-
/** A `TryStmt` which covers the full body of a function. */
26-
class FullFunctionBodyTryStmt extends TryStmt {
27-
FullFunctionBodyTryStmt() {
28-
this instanceof FunctionTryStmt
29-
or
30-
exists(Function f, BlockStmt functionBlock |
31-
functionBlock = f.getBlock() and
32-
this = functionBlock.getStmt(0) and
33-
(
34-
functionBlock.getNumStmt() = 1
35-
or
36-
functionBlock.getNumStmt() = 2 and
37-
functionBlock.getStmt(1) instanceof ReturnStmt
38-
)
39-
)
40-
}
41-
}
42-
4325
/*
4426
* The strategy for this query is to find a Stmt in the root BlockStmt which can throw one of the
4527
* ExceptionTypes that should be handled.

cpp/autosar/src/rules/A17-1-1/CStandardLibraryFunctionCalls.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import cpp
1818
import codingstandards.cpp.autosar
1919
import codingstandards.cpp.Naming
20+
import codingstandards.cpp.StdNamespace
2021

2122
FunctionCall nonCompliantCStdlibCalls(File f) {
2223
result =
@@ -55,7 +56,7 @@ FunctionCall nonCompliantCStdlibCalls(File f) {
5556
nq = fc.getNameQualifier() and
5657
(
5758
nq.getQualifyingElement() instanceof GlobalNamespace or
58-
nq.getQualifyingElement() instanceof StdNamespace
59+
nq.getQualifyingElement() instanceof StdNS
5960
)
6061
)
6162
)

cpp/autosar/src/rules/A18-1-1/CStyleArraysUsed.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ class StaticConstExprArrayDataMember extends MemberVariable {
3030
from Variable v
3131
where
3232
not isExcluded(v, BannedSyntaxPackage::cStyleArraysUsedQuery()) and
33-
exists(ArrayType a | v.getType() = a | not v instanceof StaticConstExprArrayDataMember)
33+
exists(ArrayType a | v.getType() = a | not v instanceof StaticConstExprArrayDataMember) and
34+
// Exclude the compiler generated __func__ as it is the only way to access the function name information
35+
not v.getName() = "__func__"
3436
select v, "Variable " + v.getName() + " declares a c-style array."

cpp/autosar/src/rules/A18-1-2/VectorboolSpecializationUsed.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
import cpp
1919
import codingstandards.cpp.autosar
20+
import codingstandards.cpp.StdNamespace
2021

2122
predicate isVectorBool(ClassTemplateInstantiation c) {
22-
c.getNamespace() instanceof StdNamespace and
23+
c.getNamespace() instanceof StdNS and
2324
c.getTemplateArgument(0) instanceof BoolType and
2425
c.getSimpleName() = "vector"
2526
}

cpp/autosar/src/rules/A18-1-3/AutoPtrTypeUsed.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18+
import codingstandards.cpp.StdNamespace
1819

1920
predicate isAutoPtr(ClassTemplateInstantiation c) {
20-
c.getNamespace() instanceof StdNamespace and
21+
c.getNamespace() instanceof StdNS and
2122
c.getSimpleName() = "auto_ptr"
2223
}
2324

cpp/autosar/src/rules/A18-9-1/BindUsed.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18+
import codingstandards.cpp.StdNamespace
1819

1920
predicate isBind(FunctionCall fc) {
20-
fc.getTarget().getQualifiedName() in ["std::bind", "std::bind1st", "std::bind2nd"]
21+
fc.getTarget().getNamespace() instanceof StdNS and
22+
fc.getTarget().getName() in ["bind", "bind1st", "bind2nd"]
2123
}
2224

2325
from FunctionCall fc
2426
where
2527
isBind(fc) and
2628
not isExcluded(fc, BannedFunctionsPackage::bindUsedQuery())
27-
select fc, "Prefer lambdas to using " + fc.getTarget().getQualifiedName() + "."
29+
select fc, "Prefer lambdas to using `" + fc.getTarget().getName() + "`."

cpp/autosar/src/rules/A2-13-3/TypeWcharTUsed.ql

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ predicate isUsingWideCharType(ClassTemplateInstantiation c) {
2626

2727
from Variable v
2828
where
29-
v.getUnderlyingType() instanceof WideCharType and
30-
not v.isFromTemplateInstantiation(_)
31-
or
32-
exists(ClassTemplateInstantiation c |
33-
c = v.getType() and
34-
isUsingWideCharType(c)
35-
) and
36-
not isExcluded(v, BannedTypesPackage::typeWcharTUsedQuery())
29+
not isExcluded(v, BannedTypesPackage::typeWcharTUsedQuery()) and
30+
(
31+
v.getUnderlyingType() instanceof WideCharType and
32+
not v.isFromTemplateInstantiation(_)
33+
or
34+
exists(ClassTemplateInstantiation c |
35+
c = v.getType() and
36+
isUsingWideCharType(c)
37+
)
38+
)
3739
select v, "Use of wchar_t type."

cpp/autosar/src/rules/A27-0-4/CStyleStringsUsed.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ where
3636
e = any(FunctionCall fc).getArgument(_) and
3737
e.getUnspecifiedType().(PointerType).getBaseType*() instanceof CharType
3838
) and
39-
DataFlow::localFlow(DataFlow::exprNode(cs), DataFlow::exprNode(e))
39+
DataFlow::localFlow(DataFlow::exprNode(cs), DataFlow::exprNode(e)) and
40+
not cs = any(LocalVariable lv | lv.getName() = "__func__").getInitializer().getExpr()
4041
select cs, "Usage of C-style string in $@.", e, "expression"

cpp/autosar/src/rules/A7-1-5/AutoSpecifierNotUsedAppropriatelyInVariableDefinition.ql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
import cpp
2020
import codingstandards.cpp.autosar
2121

22-
// for readability we define a "fundamental" type
23-
class FundamentalType extends Type {
24-
FundamentalType() { this instanceof BuiltInType }
25-
}
26-
2722
from Variable v
2823
where
2924
not isExcluded(v,

cpp/autosar/src/rules/A8-4-4/FunctionReturnMultipleValueCondition.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ OutputValue getAnOutputValue(Function f) {
5050

5151
from Function f, int outputValues
5252
where
53+
not isExcluded(f, FunctionsPackage::functionReturnMultipleValueConditionQuery()) and
5354
not f.isCompilerGenerated() and
5455
not f.isAffectedByMacro() and
5556
not f.isFromUninstantiatedTemplate(_) and

cpp/autosar/src/rules/M17-0-5/SetjmpMacroAndTheLongjmpFunctionUsed.ql

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18+
import codingstandards.cpp.rules.donotusesetjmporlongjmpshared.DoNotUseSetjmpOrLongjmpShared
1819

19-
predicate isLongJumpCall(FunctionCall fc) { fc.getTarget().hasGlobalOrStdName("longjmp") }
20-
21-
predicate isSetJumpCall(MacroInvocation mi) { mi.getMacroName() = "setjmp" }
22-
23-
from Element jmp, string callType
24-
where
25-
not isExcluded(jmp, BannedFunctionsPackage::setjmpMacroAndTheLongjmpFunctionUsedQuery()) and
26-
(
27-
isLongJumpCall(jmp) and callType = "longjmp function"
28-
or
29-
isSetJumpCall(jmp) and callType = "setjmp macro"
30-
)
31-
select jmp, "Use of banned " + callType + "."
20+
class SetjmpMacroAndTheLongjmpFunctionUsedQuery extends DoNotUseSetjmpOrLongjmpSharedSharedQuery {
21+
SetjmpMacroAndTheLongjmpFunctionUsedQuery() {
22+
this = BannedFunctionsPackage::setjmpMacroAndTheLongjmpFunctionUsedQuery()
23+
}
24+
}

cpp/autosar/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/autosar-cpp-coding-standards-tests
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

cpp/autosar/test/rules/A0-4-1/FloatingPointImplementationShallComplyWithIeeeStandard.expected.qcc

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <limits>
2+
3+
void test() {
4+
float f; // COMPLIANT
5+
6+
double d; // COMPLIANT
7+
long double ld; // COMPLIANT
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <limits>
2+
3+
void test() {
4+
float f; // COMPLIANT
5+
6+
double d; // COMPLIANT
7+
long double ld; // COMPLIANT
8+
}

0 commit comments

Comments
 (0)