Skip to content

Commit 7e84453

Browse files
authored
Merge pull request #2542 from geoffw0/datetime
C++: Sort through the leap year and japanese era queries
2 parents f921cf7 + b2e2db1 commit 7e84453

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

change-notes/1.24/analysis-cpp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The following changes in version 1.24 affect C/C++ analysis in all applications.
1919
| Memory may not be freed (`cpp/memory-may-not-be-freed`) | More true positive results | This query now identifies a wider variety of buffer allocations using the `semmle.code.cpp.models.interfaces.Allocation` library. |
2020
| Hard-coded Japanese era start date (`cpp/japanese-era/exact-era-date`) | | This query is no longer run on LGTM. |
2121
| No space for zero terminator (`cpp/no-space-for-terminator`) | Fewer false positive results | This query has been modified to be more conservative when identifying which pointers point to null-terminated strings. This approach produces fewer, more accurate results. |
22+
| Unsafe array for days of the year (`cpp/leap-year/unsafe-array-for-days-of-the-year`) | | This query is no longer run on LGTM. |
2223

2324
## Changes to libraries
2425

cpp/ql/src/Best Practices/Magic Constants/JapaneseEraDate.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* @problem.severity warning
66
* @id cpp/japanese-era/exact-era-date
77
* @precision low
8-
* @tags reliability
8+
* @tags maintainability
9+
* reliability
910
* japanese-era
1011
*/
1112

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @id cpp/leap-year/adding-365-days-per-year
99
* @precision medium
1010
* @tags leap-year
11+
* correctness
1112
*/
1213

1314
import cpp

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @id cpp/leap-year/unchecked-after-arithmetic-year-modification
77
* @precision medium
88
* @tags leap-year
9+
* correctness
910
*/
1011

1112
import cpp

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @id cpp/leap-year/unchecked-return-value-for-time-conversion-function
99
* @precision medium
1010
* @tags leap-year
11+
* correctness
1112
*/
1213

1314
import cpp

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @kind problem
66
* @problem.severity warning
77
* @id cpp/leap-year/unsafe-array-for-days-of-the-year
8-
* @precision medium
8+
* @precision low
99
* @tags security
1010
* leap-year
1111
*/

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@ import cpp
1010
class PackedTimeType extends Type {
1111
PackedTimeType() {
1212
this.getName() = "_FILETIME" or
13-
this.getName().matches("_FILETIME %")
13+
this.(DerivedType).getBaseType*().getName() = "_FILETIME"
1414
}
1515
}
1616

17+
private predicate timeType(string typeName) {
18+
typeName = "_SYSTEMTIME" or
19+
typeName = "SYSTEMTIME" or
20+
typeName = "tm"
21+
}
22+
1723
/**
1824
* A type that is used to represent times and dates in an 'unpacked' form, that is,
1925
* with separate fields for day, month, year etc.
2026
*/
2127
class UnpackedTimeType extends Type {
2228
UnpackedTimeType() {
23-
this.getName() = "_SYSTEMTIME" or
24-
this.getName() = "SYSTEMTIME" or
25-
this.getName() = "tm" or
26-
this.getName().matches("_SYSTEMTIME %") or
27-
this.getName().matches("SYSTEMTIME %") or
28-
this.getName().matches("tm %")
29+
timeType(this.getName()) or
30+
timeType(this.(DerivedType).getBaseType*().getName())
2931
}
3032
}
3133

0 commit comments

Comments
 (0)