Skip to content

Commit

Permalink
Merge commit 'b9b508e47b3aa62481e30b792a3c1d91f1848081' into codeql/u…
Browse files Browse the repository at this point in the history
…pgrade-to-2.15.5
  • Loading branch information
lcartey committed Oct 4, 2024
2 parents c9a7b05 + b9b508e commit 0d86495
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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
Expand Down Expand Up @@ -179,7 +178,7 @@ predicate isInappropriateEssentialType(
child =
[
operator.(BinaryBitwiseOperation).getAnOperand(),
operator.(Bitwise::AssignBitwiseOperation).getAnOperand(),
operator.(AssignBitwiseOperation).getAnOperand(),
operator.(ComplementExpr).getAnOperand()
] and
not operator instanceof LShiftExpr and
Expand Down
10 changes: 4 additions & 6 deletions c/misra/src/rules/RULE-8-2/FunctionTypesNotInPrototypeForm.ql
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,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
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.Bitwise
import codingstandards.cpp.Conversion

predicate isBinaryBitwiseOperation(Operation o, VariableAccess l, VariableAccess r) {
exists(BinaryBitwiseOperation bbo | bbo = o |
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()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.Bitwise

from Operation o, VariableAccess va
where
not isExcluded(o, ExpressionsPackage::bitwiseOperatorAppliedToSignedTypesQuery()) and
(
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.Bitwise

class ShiftOperation extends Operation {
Expr leftOperand;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 |
Expand All @@ -9,6 +10,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 |
Expand All @@ -20,3 +23,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 |
5 changes: 3 additions & 2 deletions cpp/cert/test/rules/MEM53-CPP/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
20 changes: 0 additions & 20 deletions cpp/common/src/codingstandards/cpp/Bitwise.qll

This file was deleted.

0 comments on commit 0d86495

Please sign in to comment.