|
4 | 4 | * @kind problem |
5 | 5 | * @problem.severity warning |
6 | 6 | * @id cpp/japanese-era/struct-with-exact-era-date |
| 7 | + * @precision medium |
7 | 8 | * @tags reliability |
8 | 9 | * japanese-era |
9 | 10 | */ |
10 | 11 |
|
11 | 12 | import cpp |
12 | 13 | import semmle.code.cpp.commons.DateTime |
13 | 14 |
|
| 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 | + |
14 | 42 | 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 |
17 | 44 | 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) |
27 | 48 | select year, "A time struct that is initialized with exact Japanese calendar era start date." |
0 commit comments