X Tutup
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.
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
2 changes: 2 additions & 0 deletions cpp/common/src/codingstandards/cpp/lifetimes/CppObjects.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

borrowed this from here

Comment on lines +265 to +266
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class docstring says "An object identified by a call to malloc" but now also includes new/new[] expressions (excluding placement new). The documentation should be updated to reflect the expanded scope, e.g. "An object identified by a dynamic allocation expression (malloc, new, new[])."

Copilot uses AI. Check for mistakes.
}

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