Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7e49686

Browse files
committed
A18-1-4: Fix compiler compatibility issues with reset
reset() is sometimes declared on a base class. Similar issue to A8-4-13, so Ihave refactored the SmartPointer class to provide predicates which identifythe operations across multiple compilers.
1 parent25bc94d commit7e49686

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

‎cpp/autosar/src/rules/A18-1-4/PointerToAnElementOfAnArrayPassedToASmartPointer.ql‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,7 @@ class SingleObjectSmartPointerArrayConstructionConfig extends TaintTracking::Con
4646
(
4747
sp.getAConstructorCallWithExternalObjectConstruction().getAnArgument()=sink.asExpr()
4848
or
49-
sink.asExpr()=
50-
any(FunctionCallfc,MemberFunctionmf|
51-
mf=fc.getTarget()and
52-
mf.getDeclaringType()=spand
53-
mf.getName()="reset"
54-
|
55-
fc.getArgument(0)
56-
)
49+
sink.asExpr()=sp.getAResetCall().getArgument(0)
5750
)
5851
)
5952
}

‎cpp/autosar/src/rules/A8-4-13/SharedPtrPassedToFunctionWithImproperSemantics.ql‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,20 @@ import cpp
1919
import codingstandards.cpp.autosar
2020
import codingstandards.cpp.SmartPointers
2121

22-
classAutosarSharedPointerOrDerivedextendsType{
23-
AutosarSharedPointerOrDerived(){
24-
this.getUnspecifiedType()instanceofAutosarSharedPointeror
25-
this.getUnspecifiedType().(DerivedType).getBaseType()instanceofAutosarSharedPointer
26-
}
27-
}
28-
29-
ExprunderlyingObjectAffectingSharedPointerExpr(Functionf){
30-
result=
31-
any(VariableAccessva,FunctionCallfc|
32-
va.getEnclosingFunction()=fand
33-
// The type of the variable is either a shared_ptr, or a reference or pointer to a shared_ptr
34-
va.getType()instanceofAutosarSharedPointerOrDerivedand
35-
fc.getQualifier()=vaand
36-
// include only calls to methods which modify the underlying object
37-
fc.getTarget().hasName(["operator=","reset","swap"])
38-
|
39-
va
40-
)
22+
VariableAccessunderlyingObjectAffectingSharedPointerExpr(Functionf){
23+
exists(FunctionCallfc|
24+
// Find a call in the function
25+
fc.getEnclosingFunction()=fand
26+
// include only calls to methods which modify the underlying object
27+
fc=any(AutosarSharedPointers).getAModifyingCall()and
28+
// Report the qualifier
29+
fc.getQualifier()=result
30+
)
4131
}
4232

4333
predicateflowsToUnderlyingObjectAffectingExpr(Parameterp){
4434
// check if a parameter flows locally to an expression which affects smart pointer lifetime
45-
p.getType()instanceofAutosarSharedPointerOrDerivedand
35+
p.getType().stripType()instanceofAutosarSharedPointerand
4636
localExprFlow(p.getAnAccess(),underlyingObjectAffectingSharedPointerExpr(p.getFunction()))
4737
or
4838
// else handle nested cases, such as passing smart pointers as reference arguments
@@ -60,7 +50,7 @@ predicate flowsToUnderlyingObjectAffectingExpr(Parameter p) {
6050
fromDefinedSmartPointerParameterp,stringproblem
6151
where
6252
notisExcluded(p, SmartPointers1Package::smartPointerAsParameterWithoutLifetimeSemanticsQuery())and
63-
p.getType()instanceofAutosarSharedPointerOrDerivedand
53+
p.getType().stripType()instanceofAutosarSharedPointerand
6454
(
6555
// handle the parameter depending on its derived type
6656
p.getType()instanceofRValueReferenceTypeand

‎cpp/common/src/codingstandards/cpp/SmartPointers.qll‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ abstract class AutosarSmartPointer extends Class {
5151
AutosarSmartPointer
5252
)
5353
}
54+
55+
FunctionCallgetAResetCall(){
56+
result.getTarget().hasName("reset")and
57+
result.getQualifier().getType().stripType()=this
58+
}
59+
60+
FunctionCallgetAModifyingCall(){
61+
result.getTarget().hasName(["operator=","reset","swap"])and
62+
result.getQualifier().getType().stripType()=this
63+
}
5464
}
5565

5666
classAutosarUniquePointerextendsAutosarSmartPointer{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp