From 66dffdde054e033915c3ab014fd8f24db6d1424d Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 25 Jun 2019 15:18:28 +0100 Subject: [PATCH] CPP: Correct overuse of 'toString'. --- cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll | 8 +++--- .../src/semmle/code/cpp/commons/DateTime.qll | 28 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll b/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll index bc6ed73afc8..8362f611044 100644 --- a/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll +++ b/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll @@ -35,7 +35,7 @@ class CheckForLeapYearOperation extends Operation { CheckForLeapYearOperation() { exists(BinaryArithmeticOperation bo | bo = this | bo.getAnOperand().getValue().toInt() = 4 and - bo.getOperator().toString() = "%" and + bo.getOperator() = "%" and additionalLogicalCheck(this.getEnclosingElement(), "%", 100) and additionalLogicalCheck(this.getEnclosingElement(), "%", 400) ) @@ -144,7 +144,7 @@ abstract class LeapYearFieldAccess extends YearFieldAccess { exists(BinaryArithmeticOperation bo | bo.getAnOperand() = this and bo.getAnOperand().getValue().toInt() = 4 and - bo.getOperator().toString() = "%" + bo.getOperator() = "%" ) } @@ -168,14 +168,14 @@ abstract class LeapYearFieldAccess extends YearFieldAccess { * `YearFieldAccess` for the `SYSTEMTIME` struct. */ class StructSystemTimeLeapYearFieldAccess extends LeapYearFieldAccess { - StructSystemTimeLeapYearFieldAccess() { this.toString() = "wYear" } + StructSystemTimeLeapYearFieldAccess() { this.getTarget().getName() = "wYear" } } /** * `YearFieldAccess` for `struct tm`. */ class StructTmLeapYearFieldAccess extends LeapYearFieldAccess { - StructTmLeapYearFieldAccess() { this.toString() = "tm_year" } + StructTmLeapYearFieldAccess() { this.getTarget().getName() = "tm_year" } override predicate isUsedInCorrectLeapYearCheck() { this.isUsedInMod4Operation() and diff --git a/cpp/ql/src/semmle/code/cpp/commons/DateTime.qll b/cpp/ql/src/semmle/code/cpp/commons/DateTime.qll index 259a0fa1d65..503ce09d5be 100644 --- a/cpp/ql/src/semmle/code/cpp/commons/DateTime.qll +++ b/cpp/ql/src/semmle/code/cpp/commons/DateTime.qll @@ -9,8 +9,8 @@ import cpp */ class FileTimeStruct extends Type { FileTimeStruct() { - this.toString() = "_FILETIME" - or this.toString().matches("_FILETIME %") + this.getName() = "_FILETIME" + or this.getName().matches("_FILETIME %") } } @@ -20,12 +20,12 @@ class FileTimeStruct extends Type { */ class DateDataStruct extends Type { DateDataStruct() { - this.toString() = "_SYSTEMTIME" - or this.toString() = "SYSTEMTIME" - or this.toString() = "tm" - or this.toString().matches("_SYSTEMTIME %") - or this.toString().matches("SYSTEMTIME %") - or this.toString().matches("tm %") + this.getName() = "_SYSTEMTIME" + or this.getName() = "SYSTEMTIME" + or this.getName() = "tm" + or this.getName().matches("_SYSTEMTIME %") + or this.getName().matches("SYSTEMTIME %") + or this.getName().matches("tm %") } } @@ -61,7 +61,7 @@ abstract class YearFieldAccess extends StructFieldAccess {} */ class SystemTimeDayFieldAccess extends DayFieldAccess { SystemTimeDayFieldAccess () { - this.toString() = "wDay" + this.getTarget().getName() = "wDay" } } @@ -70,7 +70,7 @@ class SystemTimeDayFieldAccess extends DayFieldAccess { */ class SystemTimeMonthFieldAccess extends MonthFieldAccess { SystemTimeMonthFieldAccess () { - this.toString() = "wMonth" + this.getTarget().getName() = "wMonth" } } @@ -79,7 +79,7 @@ class SystemTimeMonthFieldAccess extends MonthFieldAccess { */ class StructSystemTimeYearFieldAccess extends YearFieldAccess { StructSystemTimeYearFieldAccess() { - this.toString() = "wYear" + this.getTarget().getName() = "wYear" } } @@ -88,7 +88,7 @@ class StructSystemTimeYearFieldAccess extends YearFieldAccess { */ class StructTmDayFieldAccess extends DayFieldAccess { StructTmDayFieldAccess() { - this.toString() = "tm_mday" + this.getTarget().getName() = "tm_mday" } } @@ -97,7 +97,7 @@ class StructTmDayFieldAccess extends DayFieldAccess { */ class StructTmMonthFieldAccess extends MonthFieldAccess { StructTmMonthFieldAccess() { - this.toString() = "tm_mon" + this.getTarget().getName() = "tm_mon" } } @@ -106,6 +106,6 @@ class StructTmMonthFieldAccess extends MonthFieldAccess { */ class StructTmYearFieldAccess extends YearFieldAccess { StructTmYearFieldAccess() { - this.toString() = "tm_year" + this.getTarget().getName() = "tm_year" } }