Skip to content

Commit 364100f

Browse files
authored
Merge pull request #1480 from geoffw0/time
CPP: Speed up StructWithExactEraDate.ql
2 parents 524a184 + 0e69063 commit 364100f

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

cpp/ql/src/Likely Bugs/JapaneseEra/StructWithExactEraDate.ql

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,45 @@
44
* @kind problem
55
* @problem.severity warning
66
* @id cpp/japanese-era/struct-with-exact-era-date
7+
* @precision medium
78
* @tags reliability
89
* japanese-era
910
*/
1011

1112
import cpp
1213
import semmle.code.cpp.commons.DateTime
1314

15+
predicate assignedYear(Struct s, YearFieldAccess year, int value)
16+
{
17+
exists(Operation yearAssignment |
18+
s.getAField().getAnAccess() = year and
19+
yearAssignment.getAnOperand() = year and
20+
yearAssignment.getAnOperand().getValue().toInt() = value
21+
)
22+
}
23+
24+
predicate assignedMonth(Struct s, MonthFieldAccess month, int value)
25+
{
26+
exists(Operation monthAssignment |
27+
s.getAField().getAnAccess() = month and
28+
monthAssignment.getAnOperand() = month and
29+
monthAssignment.getAnOperand().getValue().toInt() = value
30+
)
31+
}
32+
33+
predicate assignedDay(Struct s, DayFieldAccess day, int value)
34+
{
35+
exists(Operation dayAssignment |
36+
s.getAField().getAnAccess() = day and
37+
dayAssignment.getAnOperand() = day and
38+
dayAssignment.getAnOperand().getValue().toInt() = value
39+
)
40+
}
41+
1442
from
15-
StructLikeClass s, YearFieldAccess year, MonthFieldAccess month, DayFieldAccess day,
16-
Operation yearAssignment, Operation monthAssignment, Operation dayAssignment
43+
StructLikeClass s, YearFieldAccess year, MonthFieldAccess month, DayFieldAccess day
1744
where
18-
s.getAField().getAnAccess() = year and
19-
yearAssignment.getAnOperand() = year and
20-
yearAssignment.getAnOperand().getValue().toInt() = 1989 and
21-
s.getAField().getAnAccess() = month and
22-
monthAssignment.getAnOperand() = month and
23-
monthAssignment.getAnOperand().getValue().toInt() = 1 and
24-
s.getAField().getAnAccess() = day and
25-
dayAssignment.getAnOperand() = day and
26-
dayAssignment.getAnOperand().getValue().toInt() = 8
45+
assignedYear(s, year, 1989) and
46+
assignedMonth(s, month, 1) and
47+
assignedDay(s, day, 8)
2748
select year, "A time struct that is initialized with exact Japanese calendar era start date."

0 commit comments

Comments
 (0)