Commit a37492c
sint4korr (non-x86 path): the expression
`(int16)(A)[3] << 24` causes signed integer overflow
when byte value >= 128, since 128<<24 exceeds INT32_MAX.
Redefine as `(int32) uint4korr(A)` to compute in unsigned
arithmetic, matching the server (my_byteorder.h:137-140).
The next line sint8korr already uses this same pattern:
`(longlong) uint8korr(A)`.
convert_from_long (MYSQL_TYPE_DOUBLE, MYSQL_TYPE_FLOAT):
casting double/float back to ulonglong/longlong for
truncation detection is undefined when the float value
is outside the representable integer range. For example,
`(double)ULONGLONG_MAX` rounds up to 2^64 in IEEE 754
(not exactly representable with 53-bit mantissa), so
`(ulonglong)dbl` overflows. Similarly for LONGLONG_MAX.
Add range checks before the cast using `>=` for upper
bounds (since the double rounds up past the integer max)
and `<` for LONGLONG_MIN (exactly representable as -2^63).
Out-of-range values set the truncation error flag directly,
short-circuiting the dangerous cast via `||` evaluation.
This matches the server pattern in sql/field.cc and
sql/sql_select.cc (double_to_ulonglong macro).
Co-Authored-By: Claude AI <noreply@anthropic.com>
1 parent c44bc3b commit a37492c
2 files changed
Lines changed: 23 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
838 | 838 | | |
839 | 839 | | |
840 | 840 | | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
| 841 | + | |
845 | 842 | | |
846 | 843 | | |
847 | 844 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
633 | 633 | | |
634 | 634 | | |
635 | 635 | | |
636 | | - | |
637 | | - | |
638 | | - | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
639 | 646 | | |
640 | 647 | | |
641 | 648 | | |
| |||
645 | 652 | | |
646 | 653 | | |
647 | 654 | | |
648 | | - | |
649 | | - | |
650 | | - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
651 | 667 | | |
652 | 668 | | |
653 | 669 | | |
| |||
0 commit comments