Commit 3ac0971
ARROW-8924: [C++][Gandiva] Avoid potential int overflow in castDATE_date32()
This PR avoids the potential int overflow due to int32 multiplication in castDATE_date32().
In https://github.com/apache/arrow/blob/master/cpp/src/gandiva/precompiled/time.cc#L461, the following code performs the multiplication of two `int32`. The result is also `int32`. Then, the result is converted to `int64`.
This code may cause overflow if the result is more than 32-bit. To avoid the overflow, this PR pre-casts the constant to `int64`. As a result, the multiplication will become `int64` * `int64`.
```
gdv_date64 castDATE_date32(gdv_date32 days) { return days * MILLIS_IN_DAY; }
```
This can fix the following failure:
```
The following tests FAILED:
67 - gandiva-date-time-test (Failed)
```
Closes apache#7260 from kiszk/ARROW-8924
Authored-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>1 parent 4f3601f commit 3ac0971
1 file changed
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
461 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
462 | 464 | | |
463 | 465 | | |
464 | 466 | | |
| |||
0 commit comments