Skip to content

Commit bc5fb24

Browse files
committed
CPP: Correct overuse of 'matches'.
1 parent ab543aa commit bc5fb24

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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().matches("wYear") }
171+
StructSystemTimeLeapYearFieldAccess() { this.toString() = "wYear" }
172172
}
173173

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

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

cpp/ql/src/Likely Bugs/Leap Year/UncheckedReturnValueForTimeFunctions.ql

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class DateStructModifiedFieldAccess extends LeapYearFieldAccess {
3737
*/
3838
class SafeTimeGatheringFunction extends Function {
3939
SafeTimeGatheringFunction() {
40-
this.getQualifiedName().matches("GetFileTime") or
41-
this.getQualifiedName().matches("GetSystemTime") or
42-
this.getQualifiedName().matches("NtQuerySystemTime")
40+
this.getQualifiedName() = "GetFileTime" or
41+
this.getQualifiedName() = "GetSystemTime" or
42+
this.getQualifiedName() = "NtQuerySystemTime"
4343
}
4444
}
4545

@@ -48,15 +48,15 @@ class SafeTimeGatheringFunction extends Function {
4848
*/
4949
class TimeConversionFunction extends Function {
5050
TimeConversionFunction() {
51-
this.getQualifiedName().matches("FileTimeToSystemTime") or
52-
this.getQualifiedName().matches("SystemTimeToFileTime") or
53-
this.getQualifiedName().matches("SystemTimeToTzSpecificLocalTime") or
54-
this.getQualifiedName().matches("SystemTimeToTzSpecificLocalTimeEx") or
55-
this.getQualifiedName().matches("TzSpecificLocalTimeToSystemTime") or
56-
this.getQualifiedName().matches("TzSpecificLocalTimeToSystemTimeEx") or
57-
this.getQualifiedName().matches("RtlLocalTimeToSystemTime") or
58-
this.getQualifiedName().matches("RtlTimeToSecondsSince1970") or
59-
this.getQualifiedName().matches("_mkgmtime")
51+
this.getQualifiedName() = "FileTimeToSystemTime" or
52+
this.getQualifiedName() = "SystemTimeToFileTime" or
53+
this.getQualifiedName() = "SystemTimeToTzSpecificLocalTime" or
54+
this.getQualifiedName() = "SystemTimeToTzSpecificLocalTimeEx" or
55+
this.getQualifiedName() = "TzSpecificLocalTimeToSystemTime" or
56+
this.getQualifiedName() = "TzSpecificLocalTimeToSystemTimeEx" or
57+
this.getQualifiedName() = "RtlLocalTimeToSystemTime" or
58+
this.getQualifiedName() = "RtlTimeToSecondsSince1970" or
59+
this.getQualifiedName() = "_mkgmtime"
6060
}
6161
}
6262

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import cpp
99
*/
1010
class FileTimeStruct extends Type {
1111
FileTimeStruct() {
12-
this.toString().matches("_FILETIME")
12+
this.toString() = "_FILETIME"
1313
or this.toString().matches("_FILETIME %")
1414
}
1515
}
@@ -20,9 +20,9 @@ class FileTimeStruct extends Type {
2020
*/
2121
class DateDataStruct extends Type {
2222
DateDataStruct() {
23-
this.toString().matches("_SYSTEMTIME")
24-
or this.toString().matches("SYSTEMTIME")
25-
or this.toString().matches("tm")
23+
this.toString() = "_SYSTEMTIME"
24+
or this.toString() = "SYSTEMTIME"
25+
or this.toString() = "tm"
2626
or this.toString().matches("_SYSTEMTIME %")
2727
or this.toString().matches("SYSTEMTIME %")
2828
or this.toString().matches("tm %")
@@ -61,7 +61,7 @@ abstract class YearFieldAccess extends StructFieldAccess {}
6161
*/
6262
class SystemTimeDayFieldAccess extends DayFieldAccess {
6363
SystemTimeDayFieldAccess () {
64-
this.toString().matches("wDay")
64+
this.toString() = "wDay"
6565
}
6666
}
6767

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

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

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

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

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

0 commit comments

Comments
 (0)