mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
[ruby/yarp] Fix wrong conversion and cast
Conversions from `uint64_t`/`VALUE` to `long` may loose upper bits.
c26f650d96
This commit is contained in:
parent
d931bf2232
commit
397a77557c
1 changed files with 11 additions and 1 deletions
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue