Skip to content

Commit

Permalink
Query formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRFairhurst committed Nov 28, 2024
1 parent f73df15 commit 6169352
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ where
(
addrNode = DataFlow::exprNode(any(AddressOfExpr e | e.getOperand() = acc))
or
addrNode = DataFlow::exprNode(acc) and exists(ArrayToPointerConversion c | c.getExpr() = acc)
addrNode = DataFlow::exprNode(acc) and
exists(ArrayToPointerConversion c | c.getExpr() = acc)
) and
TaintTracking::localTaint(addrNode, DataFlow::exprNode(arg))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import codingstandards.cpp.dataflow.DataFlow

class Source extends Expr {
ObjectIdentity rootObject;

Source() {
rootObject.getStorageDuration().isAutomatic()
and this = rootObject.getASubobjectAddressExpr()
rootObject.getStorageDuration().isAutomatic() and
this = rootObject.getASubobjectAddressExpr()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ class FlexibleArrayStructDynamicAlloc extends FlexibleArrayAlloc, FunctionCall {
*/
class FlexibleArrayNonDynamicAlloc extends FlexibleArrayAlloc {
ObjectIdentity object;

FlexibleArrayNonDynamicAlloc() {
this = object and
not object.getStorageDuration().isAllocated() and
// Exclude temporaries. Though they should violate this rule, in practice these results are
// often spurious and redundant, such as (*x = *x) which creates an unused temporary object.
not object.hasTemporaryLifetime() and
object.getType().getUnspecifiedType() instanceof FlexibleArrayStructType
and not exists(Variable v | v.getInitializer().getExpr() = this)
object.getType().getUnspecifiedType() instanceof FlexibleArrayStructType and
not exists(Variable v | v.getInitializer().getExpr() = this)
}

override Element getReportElement() { result = object }
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion c/common/test/library/objects/ObjectIdentity.ql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import codingstandards.c.Objects

from ObjectIdentity obj
where obj.getFile().getBaseName() = "objectidentity.c"
select obj, obj.getStorageDuration(), obj.getType()
select obj, obj.getStorageDuration(), obj.getType()
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ Expr temporaryObjectFlowStep(Expr e) {
e = result.(ConditionalExpr).getElse()
}

from
FieldAccess fa, TemporaryObjectIdentity temporary,
ArrayToPointerConversion conversion
from FieldAccess fa, TemporaryObjectIdentity temporary, ArrayToPointerConversion conversion
where
not isExcluded(conversion, InvalidMemory3Package::arrayToPointerConversionOfTemporaryObjectQuery()) and
fa = temporary.getASubobjectAccess() and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ predicate usedAsModifiableLvalue(Expr expr, Boolean allowArrayAccess) {
exists(AddressOfExpr parent | parent.getOperand() = expr)
or
// Don't report `x.y[0].m[0]++` twice. Recurse with `allowArrayAccess` set to false.
exists(FieldAccess parent | parent.getQualifier() = expr and usedAsModifiableLvalue(parent, false))
exists(FieldAccess parent |
parent.getQualifier() = expr and usedAsModifiableLvalue(parent, false)
)
or
allowArrayAccess = true and
exists(ArrayExpr parent | parent.getArrayBase() = expr and usedAsModifiableLvalue(parent, true))
Expand Down
5 changes: 2 additions & 3 deletions c/misra/src/rules/RULE-22-14/MutexInitializedInsideThread.ql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ from C11MutexSource mutexCreate, ThreadedFunction thread
where
not isExcluded(mutexCreate, Concurrency8Package::mutexInitializedInsideThreadQuery()) and
thread.calls*(mutexCreate.getEnclosingFunction())
select
mutexCreate, "Mutex initialization reachable from threaded function '$@'.",
thread, thread.getName()
select mutexCreate, "Mutex initialization reachable from threaded function '$@'.", thread,
thread.getName()
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ThreadObjectInitialization extends FunctionCall {
class ThreadObjectUse extends Expr {
ObjectIdentity owningObject;
string typeString;

ThreadObjectUse() {
owningObject.getASubobjectAddressExpr() = this and
(
Expand Down Expand Up @@ -78,7 +79,6 @@ class ThreadObjectUse extends Expr {
}
}


predicate requiresInitializedMutexObject(
Function func, ThreadObjectUse mutexUse, ObjectIdentity owningObject
) {
Expand Down

0 comments on commit 6169352

Please sign in to comment.