diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2025-12-07 12:43:44 -0500 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-12-08 15:01:05 -0800 |
| commit | 55ea3ec00f5166423cd7dcd67e220cd264a766f6 (patch) | |
| tree | 8fe29d8d55e2c6938bc1f0f5680796354d820cbb | |
| parent | 66bda731901d4588c9df1a671022231ea0d03216 (diff) | |
Fix strict aliasing warning in rb_int128_to_numeric
If we don't have uint128, then rb_int128_to_numeric emits a strict
aliasing warning:
numeric.c:3641:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
3641 | return rb_uint128_to_numeric(*(rb_uint128_t*)&n);
| ^~~~~~~~~~~~~~~~~
| -rw-r--r-- | internal/numeric.h | 5 | ||||
| -rw-r--r-- | io_buffer.c | 5 | ||||
| -rw-r--r-- | numeric.c | 5 |
3 files changed, 9 insertions, 6 deletions
diff --git a/internal/numeric.h b/internal/numeric.h index 75181a7f16..d3905f048c 100644 --- a/internal/numeric.h +++ b/internal/numeric.h @@ -164,6 +164,11 @@ union rb_int128 { }; typedef union rb_int128 rb_int128_t; +union uint128_int128_conversion { + rb_uint128_t uint128; + rb_int128_t int128; +}; + // Conversion functions for 128-bit integers: rb_uint128_t rb_numeric_to_uint128(VALUE x); rb_int128_t rb_numeric_to_int128(VALUE x); diff --git a/io_buffer.c b/io_buffer.c index b81527ff71..55f1933194 100644 --- a/io_buffer.c +++ b/io_buffer.c @@ -1928,11 +1928,6 @@ ruby_swap128_uint(rb_uint128_t x) return result; } -union uint128_int128_conversion { - rb_uint128_t uint128; - rb_int128_t int128; -}; - static inline rb_int128_t ruby_swap128_int(rb_int128_t x) { @@ -3638,7 +3638,10 @@ rb_int128_to_numeric(rb_int128_t n) } else { // Positive value - return rb_uint128_to_numeric(*(rb_uint128_t*)&n); + union uint128_int128_conversion conversion = { + .int128 = n + }; + return rb_uint128_to_numeric(conversion.uint128); } #endif } |
