Skip to content

Commit 7379cac

Browse files
committed
STR51-CPP: value_type
1 parent 423fb59 commit 7379cac

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

cpp/cert/test/rules/STR51-CPP/tempfile

Whitespace-only changes.

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class BasicStringMemberFunctionDereferencedExpr extends BasicStringDereferencedE
4646
// basic_string::basic_string(const charT *, const Allocator &)
4747
f instanceof Constructor and
4848
f.getNumberOfParameters() <= 2 and
49-
f.getParameter(0).getType() = stringType.getConstCharTPointer() and
49+
f.getParameter(0).getType() = stringType.getValueType() and
5050
(
5151
f.getNumberOfParameters() = 2
5252
implies
@@ -58,23 +58,23 @@ class BasicStringMemberFunctionDereferencedExpr extends BasicStringDereferencedE
5858
// basic_string &basic_string::assign(const charT *)
5959
f.hasName(["append", "assign"]) and
6060
f.getNumberOfParameters() = 1 and
61-
fc.getArgument(0).getType() = stringType.getConstCharTPointer() and
61+
f.getParameter(0).getType() = stringType.getValueType() and
6262
this = fc.getArgument(0)
6363
or
6464
// basic_string &basic_string::insert(size_type, const charT *)
6565
f.hasName("insert") and
6666
f.getNumberOfParameters() = 2 and
67-
fc.getArgument(0).getType() = stringType.getSizeType() and
68-
fc.getArgument(1).getType() = stringType.getConstCharTPointer() and
67+
f.getParameter(0).getType() = stringType.getSizeType() and
68+
f.getParameter(1).getType() = stringType.getValueType() and
6969
this = fc.getArgument(1)
7070
or
7171
// basic_string &basic_string::replace(size_type, size_type, const charT *)
7272
// basic_string &basic_string::replace(const_iterator, const_iterator, const charT *)
7373
f.hasName("replace") and
7474
f.getNumberOfParameters() = 3 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
75+
f.getParameter(0).getType() = [stringType.getSizeType(), stringType.getConstIteratorType()] and
76+
f.getParameter(1).getType() = [stringType.getSizeType(), stringType.getConstIteratorType()] and
77+
f.getParameter(2).getType() = stringType.getValueType() and
7878
this = fc.getArgument(2)
7979
or
8080
// size_type basic_string::find(const charT *, size_type)
@@ -87,24 +87,24 @@ class BasicStringMemberFunctionDereferencedExpr extends BasicStringDereferencedE
8787
"find", "rfind", "find_first_of", "find_last_of", "find_first_not_of", "find_last_not_of"
8888
]) and
8989
f.getNumberOfParameters() = 2 and
90-
fc.getArgument(0).getType() = stringType.getConstCharTPointer() and
91-
fc.getArgument(1).getType() = stringType.getSizeType() and
90+
f.getParameter(0).getType() = stringType.getValueType() and
91+
f.getParameter(1).getType() = stringType.getSizeType() and
9292
this = fc.getArgument(0)
9393
or
9494
// int basic_string::compare(const charT *)
9595
// basic_string &basic_string::operator=(const charT *)
9696
// basic_string &basic_string::operator+=(const charT *)
9797
f.hasName(["compare", "operator=", "operator+="]) and
9898
f.getNumberOfParameters() = 1 and
99-
fc.getArgument(0).getType() = stringType.getConstCharTPointer() and
99+
f.getParameter(0).getType() = stringType.getValueType() and
100100
this = fc.getArgument(0)
101101
or
102102
// int basic_string::compare(size_type, size_type, const charT *)
103103
f.hasName("compare") and
104104
f.getNumberOfParameters() = 3 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
105+
f.getParameter(0).getType() = stringType.getSizeType() and
106+
f.getParameter(1).getType() = stringType.getSizeType() and
107+
f.getParameter(2).getType() = stringType.getValueType() and
108108
this = fc.getArgument(2)
109109
)
110110
}
@@ -136,7 +136,7 @@ class BasicStringNonMemberFunctionDereferencedExpr extends BasicStringDereferenc
136136
]) and
137137
f.getAParameter().getType().(ReferenceType).getBaseType().getUnspecifiedType() = stringType and
138138
exists(int param |
139-
fc.getArgument(param).getType() = stringType.getConstCharTPointer() and
139+
f.getParameter(param).getType() = stringType.getValueType() and
140140
this = fc.getArgument(param)
141141
)
142142
)

cpp/common/src/codingstandards/cpp/standardlibrary/String.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class StdBasicString extends ClassTemplateInstantiation {
1313
Type getAllocator() { result = getTemplateArgument(2) }
1414

1515
/** Gets the `const charT*` type for this `basic_string` instantiation. */
16-
PointerType getConstCharTPointer() {
16+
PointerType getValueType() {
1717
exists(SpecifiedType specType |
1818
specType = result.getBaseType() and
19-
specType.getBaseType() = getCharT() and
2019
specType.isConst() and
21-
count(specType.getASpecifier()) = 1
20+
count(specType.getASpecifier()) = 1 and
21+
(specType.getBaseType() = getCharT() or specType.getBaseType().getName() = "value_type")
2222
)
2323
}
2424

0 commit comments

Comments
 (0)