Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
"Language1",
"Language2",
"Language3",
"Lifetime",
"Linkage1",
"Linkage2",
"Literals",
Expand Down
2 changes: 2 additions & 0 deletions change_notes/2026-02-03-uninitialized-mem-improve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A8-5-0`, `EXP53-CPP`, `EXP33-C`, `RULE-9-1` - `MemoryNotInitializedBeforeItIsRead.ql`, `DoNotReadUninitializedMemory.ql`, `DoNotReadUninitializedMemory.ql`, `ObjectWithAutoStorageDurationReadBeforeInit.ql`:
- The queries listed now find uses of the operator 'new' where there is no value initialization provided. The queries listed now also uses an out of the box library to consider initialization within another function as valid initialization (`InitializationFunctions.qll`). We do not yet track finely track the initialization/use of `p` vs `*p`.
44 changes: 44 additions & 0 deletions cpp/common/src/codingstandards/cpp/exclusions/cpp/Lifetime.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
import cpp
import RuleMetadata
import codingstandards.cpp.exclusions.RuleMetadata

newtype LifetimeQuery =
TValueOfAnObjectMustNotBeReadBeforeItHasBeenSetQuery() or
TAutomaticStorageAssignedToObjectGreaterLifetimeQuery()

predicate isLifetimeQueryMetadata(Query query, string queryId, string ruleId, string category) {
query =
// `Query` instance for the `valueOfAnObjectMustNotBeReadBeforeItHasBeenSet` query
LifetimePackage::valueOfAnObjectMustNotBeReadBeforeItHasBeenSetQuery() and
queryId =
// `@id` for the `valueOfAnObjectMustNotBeReadBeforeItHasBeenSet` query
"cpp/misra/value-of-an-object-must-not-be-read-before-it-has-been-set" and
ruleId = "RULE-11-6-2" and
category = "mandatory"
or
query =
// `Query` instance for the `automaticStorageAssignedToObjectGreaterLifetime` query
LifetimePackage::automaticStorageAssignedToObjectGreaterLifetimeQuery() and
queryId =
// `@id` for the `automaticStorageAssignedToObjectGreaterLifetime` query
"cpp/misra/automatic-storage-assigned-to-object-greater-lifetime" and
ruleId = "RULE-6-8-3" and
category = "required"
}

module LifetimePackage {
Query valueOfAnObjectMustNotBeReadBeforeItHasBeenSetQuery() {
//autogenerate `Query` type
result =
// `Query` type for `valueOfAnObjectMustNotBeReadBeforeItHasBeenSet` query
TQueryCPP(TLifetimePackageQuery(TValueOfAnObjectMustNotBeReadBeforeItHasBeenSetQuery()))
}

Query automaticStorageAssignedToObjectGreaterLifetimeQuery() {
//autogenerate `Query` type
result =
// `Query` type for `automaticStorageAssignedToObjectGreaterLifetime` query
TQueryCPP(TLifetimePackageQuery(TAutomaticStorageAssignedToObjectGreaterLifetimeQuery()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import IntegerConversion
import Invariants
import Iterators
import Lambdas
import Lifetime
import Linkage1
import Linkage2
import Literals
Expand Down Expand Up @@ -133,6 +134,7 @@ newtype TCPPQuery =
TInvariantsPackageQuery(InvariantsQuery q) or
TIteratorsPackageQuery(IteratorsQuery q) or
TLambdasPackageQuery(LambdasQuery q) or
TLifetimePackageQuery(LifetimeQuery q) or
TLinkage1PackageQuery(Linkage1Query q) or
TLinkage2PackageQuery(Linkage2Query q) or
TLiteralsPackageQuery(LiteralsQuery q) or
Expand Down Expand Up @@ -221,6 +223,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
isInvariantsQueryMetadata(query, queryId, ruleId, category) or
isIteratorsQueryMetadata(query, queryId, ruleId, category) or
isLambdasQueryMetadata(query, queryId, ruleId, category) or
isLifetimeQueryMetadata(query, queryId, ruleId, category) or
isLinkage1QueryMetadata(query, queryId, ruleId, category) or
isLinkage2QueryMetadata(query, queryId, ruleId, category) or
isLiteralsQueryMetadata(query, queryId, ruleId, category) or
Expand Down
4 changes: 3 additions & 1 deletion cpp/common/src/codingstandards/cpp/lifetimes/CppObjects.qll
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class AggregateLiteralObjectIdentity extends AggregateLiteral, ObjectIdentityBas
}

/**
* An object identified by a call to `malloc`.
* An object identified by a call to `malloc` or allcoated with a `new` or `new[]` expression.
*
* Note: the malloc expression returns an address to this object, not the object itself. Therefore,
* `getAnAccess()` returns cases where this malloc result is dereferenced, and not the malloc call
Expand All @@ -262,6 +262,8 @@ class AggregateLiteralObjectIdentity extends AggregateLiteral, ObjectIdentityBas
class AllocatedObjectIdentity extends AllocationExpr, ObjectIdentityBase {
AllocatedObjectIdentity() {
this.(FunctionCall).getTarget().(AllocationFunction).requiresDealloc()
or
this = any(NewOrNewArrayExpr new | not exists(new.getPlacementPointer()))
}

override StorageDuration getStorageDuration() { result.isAllocated() }
Expand Down
Loading
Loading