[ruby/yarp] Fix wrong conversion and cast

Conversions from `uint64_t`/`VALUE` to `long` may loose upper bits.

https://github.com/ruby/yarp/commit/c26f650d96
This commit is contained in:
Nobuyoshi Nakada 2023-08-05 11:11:26 +09:00 committed by git
parent d931bf2232
commit 397a77557c

View File

@ -9,6 +9,16 @@ static VALUE v3_2_0_symbol;
static VALUE pack_symbol;
static VALUE unpack_symbol;
#if SIZEOF_UINT64_T == SIZEOF_LONG_LONG
# define UINT64T2NUM(x) ULL2NUM(x)
# define NUM2UINT64T(x) (uint64_t)NUM2ULL(x)
#elif SIZEOF_UINT64_T == SIZEOF_LONG
# define UINT64T2NUM(x) ULONG2NUM(x)
# define NUM2UINT64T(x) (uint64_t)NUM2ULONG(x)
#else
// error No uint64_t conversion
#endif
static VALUE
pack_type_to_symbol(yp_pack_type type) {
switch (type) {
@ -221,7 +231,7 @@ pack_parse(VALUE self, VALUE version_symbol, VALUE variant_symbol, VALUE format_
pack_endian_to_symbol(endian),
pack_size_to_symbol(size),
pack_length_type_to_symbol(length_type),
(long) LONG2NUM(length) };
UINT64T2NUM(length) };
rb_ary_push(directives_array, rb_class_new_instance(9, directive_args, rb_cYARPPackDirective));
}