Skip to content

Commit 423fb59

Browse files
committed
EXP60-CPP STR51-CPP
1 parent 3ab1585 commit 423fb59

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

cpp/cert/test/rules/EXP60-CPP/DoNotPassANonstandardObjectAcrossBoundaries.expected.clang

Whitespace-only changes.

cpp/cert/test/rules/EXP60-CPP/DoNotPassANonstandardObjectAcrossBoundaries.expected.gcc

Whitespace-only changes.

cpp/cert/test/rules/EXP60-CPP/DoNotPassANonstandardObjectAcrossBoundaries.expected.qcc

Whitespace-only changes.

cpp/common/src/codingstandards/cpp/Dereferenced.qll

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,36 @@ class BasicStringMemberFunctionDereferencedExpr extends BasicStringDereferencedE
4545
|
4646
// basic_string::basic_string(const charT *, const Allocator &)
4747
f instanceof Constructor and
48-
f.getNumberOfParameters() = 2 and
48+
f.getNumberOfParameters() <= 2 and
4949
f.getParameter(0).getType() = stringType.getConstCharTPointer() and
50-
f.getParameter(1).getType() = stringType.getConstAllocatorReferenceType() and
50+
(
51+
f.getNumberOfParameters() = 2
52+
implies
53+
f.getParameter(1).getType() = stringType.getConstAllocatorReferenceType()
54+
) and
5155
this = fc.getArgument(0)
5256
or
5357
// basic_string &basic_string::append(const charT *)
5458
// basic_string &basic_string::assign(const charT *)
5559
f.hasName(["append", "assign"]) and
5660
f.getNumberOfParameters() = 1 and
57-
f.getParameter(0).getType() = stringType.getConstCharTPointer() and
61+
fc.getArgument(0).getType() = stringType.getConstCharTPointer() and
5862
this = fc.getArgument(0)
5963
or
6064
// basic_string &basic_string::insert(size_type, const charT *)
6165
f.hasName("insert") and
6266
f.getNumberOfParameters() = 2 and
63-
f.getParameter(0).getType() = stringType.getSizeType() and
64-
f.getParameter(1).getType() = stringType.getConstCharTPointer() and
67+
fc.getArgument(0).getType() = stringType.getSizeType() and
68+
fc.getArgument(1).getType() = stringType.getConstCharTPointer() and
6569
this = fc.getArgument(1)
6670
or
6771
// basic_string &basic_string::replace(size_type, size_type, const charT *)
6872
// basic_string &basic_string::replace(const_iterator, const_iterator, const charT *)
6973
f.hasName("replace") and
7074
f.getNumberOfParameters() = 3 and
71-
f.getParameter(0).getType() = [stringType.getSizeType(), stringType.getConstIteratorType()] and
72-
f.getParameter(1).getType() = [stringType.getSizeType(), stringType.getConstIteratorType()] and
73-
f.getParameter(2).getType() = stringType.getConstCharTPointer() and
75+
fc.getArgument(0).getType() = [stringType.getSizeType(), stringType.getConstIteratorType()] and
76+
fc.getArgument(1).getType() = [stringType.getSizeType(), stringType.getConstIteratorType()] and
77+
fc.getArgument(2).getType() = stringType.getConstCharTPointer() and
7478
this = fc.getArgument(2)
7579
or
7680
// size_type basic_string::find(const charT *, size_type)
@@ -83,24 +87,24 @@ class BasicStringMemberFunctionDereferencedExpr extends BasicStringDereferencedE
8387
"find", "rfind", "find_first_of", "find_last_of", "find_first_not_of", "find_last_not_of"
8488
]) and
8589
f.getNumberOfParameters() = 2 and
86-
f.getParameter(0).getType() = stringType.getConstCharTPointer() and
87-
f.getParameter(1).getType() = stringType.getSizeType() and
90+
fc.getArgument(0).getType() = stringType.getConstCharTPointer() and
91+
fc.getArgument(1).getType() = stringType.getSizeType() and
8892
this = fc.getArgument(0)
8993
or
9094
// int basic_string::compare(const charT *)
9195
// basic_string &basic_string::operator=(const charT *)
9296
// basic_string &basic_string::operator+=(const charT *)
9397
f.hasName(["compare", "operator=", "operator+="]) and
9498
f.getNumberOfParameters() = 1 and
95-
f.getParameter(0).getType() = stringType.getConstCharTPointer() and
99+
fc.getArgument(0).getType() = stringType.getConstCharTPointer() and
96100
this = fc.getArgument(0)
97101
or
98102
// int basic_string::compare(size_type, size_type, const charT *)
99103
f.hasName("compare") and
100104
f.getNumberOfParameters() = 3 and
101-
f.getParameter(0).getType() = stringType.getSizeType() and
102-
f.getParameter(1).getType() = stringType.getSizeType() and
103-
f.getParameter(2).getType() = stringType.getConstCharTPointer() and
105+
fc.getArgument(0).getType() = stringType.getSizeType() and
106+
fc.getArgument(1).getType() = stringType.getSizeType() and
107+
fc.getArgument(2).getType() = stringType.getConstCharTPointer() and
104108
this = fc.getArgument(2)
105109
)
106110
}
@@ -132,7 +136,7 @@ class BasicStringNonMemberFunctionDereferencedExpr extends BasicStringDereferenc
132136
]) and
133137
f.getAParameter().getType().(ReferenceType).getBaseType().getUnspecifiedType() = stringType and
134138
exists(int param |
135-
f.getParameter(param).getType() = stringType.getConstCharTPointer() and
139+
fc.getArgument(param).getType() = stringType.getConstCharTPointer() and
136140
this = fc.getArgument(param)
137141
)
138142
)

0 commit comments

Comments
 (0)