Skip to content

Commit 66dffdd

Browse files
committed
CPP: Correct overuse of 'toString'.
1 parent bc5fb24 commit 66dffdd

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CheckForLeapYearOperation extends Operation {
3535
CheckForLeapYearOperation() {
3636
exists(BinaryArithmeticOperation bo | bo = this |
3737
bo.getAnOperand().getValue().toInt() = 4 and
38-
bo.getOperator().toString() = "%" and
38+
bo.getOperator() = "%" and
3939
additionalLogicalCheck(this.getEnclosingElement(), "%", 100) and
4040
additionalLogicalCheck(this.getEnclosingElement(), "%", 400)
4141
)
@@ -144,7 +144,7 @@ abstract class LeapYearFieldAccess extends YearFieldAccess {
144144
exists(BinaryArithmeticOperation bo |
145145
bo.getAnOperand() = this and
146146
bo.getAnOperand().getValue().toInt() = 4 and
147-
bo.getOperator().toString() = "%"
147+
bo.getOperator() = "%"
148148
)
149149
}
150150

@@ -168,14 +168,14 @@ abstract class LeapYearFieldAccess extends YearFieldAccess {
168168
* `YearFieldAccess` for the `SYSTEMTIME` struct.
169169
*/
170170
class StructSystemTimeLeapYearFieldAccess extends LeapYearFieldAccess {
171-
StructSystemTimeLeapYearFieldAccess() { this.toString() = "wYear" }
171+
StructSystemTimeLeapYearFieldAccess() { this.getTarget().getName() = "wYear" }
172172
}
173173

174174
/**
175175
* `YearFieldAccess` for `struct tm`.
176176
*/
177177
class StructTmLeapYearFieldAccess extends LeapYearFieldAccess {
178-
StructTmLeapYearFieldAccess() { this.toString() = "tm_year" }
178+
StructTmLeapYearFieldAccess() { this.getTarget().getName() = "tm_year" }
179179

180180
override predicate isUsedInCorrectLeapYearCheck() {
181181
this.isUsedInMod4Operation() and

cpp/ql/src/semmle/code/cpp/commons/DateTime.qll

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import cpp
99
*/
1010
class FileTimeStruct extends Type {
1111
FileTimeStruct() {
12-
this.toString() = "_FILETIME"
13-
or this.toString().matches("_FILETIME %")
12+
this.getName() = "_FILETIME"
13+
or this.getName().matches("_FILETIME %")
1414
}
1515
}
1616

@@ -20,12 +20,12 @@ class FileTimeStruct extends Type {
2020
*/
2121
class DateDataStruct extends Type {
2222
DateDataStruct() {
23-
this.toString() = "_SYSTEMTIME"
24-
or this.toString() = "SYSTEMTIME"
25-
or this.toString() = "tm"
26-
or this.toString().matches("_SYSTEMTIME %")
27-
or this.toString().matches("SYSTEMTIME %")
28-
or this.toString().matches("tm %")
23+
this.getName() = "_SYSTEMTIME"
24+
or this.getName() = "SYSTEMTIME"
25+
or this.getName() = "tm"
26+
or this.getName().matches("_SYSTEMTIME %")
27+
or this.getName().matches("SYSTEMTIME %")
28+
or this.getName().matches("tm %")
2929
}
3030
}
3131

@@ -61,7 +61,7 @@ abstract class YearFieldAccess extends StructFieldAccess {}
6161
*/
6262
class SystemTimeDayFieldAccess extends DayFieldAccess {
6363
SystemTimeDayFieldAccess () {
64-
this.toString() = "wDay"
64+
this.getTarget().getName() = "wDay"
6565
}
6666
}
6767

@@ -70,7 +70,7 @@ class SystemTimeDayFieldAccess extends DayFieldAccess {
7070
*/
7171
class SystemTimeMonthFieldAccess extends MonthFieldAccess {
7272
SystemTimeMonthFieldAccess () {
73-
this.toString() = "wMonth"
73+
this.getTarget().getName() = "wMonth"
7474
}
7575
}
7676

@@ -79,7 +79,7 @@ class SystemTimeMonthFieldAccess extends MonthFieldAccess {
7979
*/
8080
class StructSystemTimeYearFieldAccess extends YearFieldAccess {
8181
StructSystemTimeYearFieldAccess() {
82-
this.toString() = "wYear"
82+
this.getTarget().getName() = "wYear"
8383
}
8484
}
8585

@@ -88,7 +88,7 @@ class StructSystemTimeYearFieldAccess extends YearFieldAccess {
8888
*/
8989
class StructTmDayFieldAccess extends DayFieldAccess {
9090
StructTmDayFieldAccess() {
91-
this.toString() = "tm_mday"
91+
this.getTarget().getName() = "tm_mday"
9292
}
9393
}
9494

@@ -97,7 +97,7 @@ class StructTmDayFieldAccess extends DayFieldAccess {
9797
*/
9898
class StructTmMonthFieldAccess extends MonthFieldAccess {
9999
StructTmMonthFieldAccess() {
100-
this.toString() = "tm_mon"
100+
this.getTarget().getName() = "tm_mon"
101101
}
102102
}
103103

@@ -106,6 +106,6 @@ class StructTmMonthFieldAccess extends MonthFieldAccess {
106106
*/
107107
class StructTmYearFieldAccess extends YearFieldAccess {
108108
StructTmYearFieldAccess() {
109-
this.toString() = "tm_year"
109+
this.getTarget().getName() = "tm_year"
110110
}
111111
}

0 commit comments

Comments
 (0)