diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-08-05 11:11:26 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-08-08 13:21:39 +0000 |
| commit | 397a77557c38fb910a5491d47720298fc18c00bc (patch) | |
| tree | 9c2cfdfc6cb1aaa18ab9e663d798eb25dd3fcebf | |
| parent | d931bf223216e87e8befebd8d631d9f25c23d564 (diff) | |
[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
| -rw-r--r-- | yarp/api_pack.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/yarp/api_pack.c b/yarp/api_pack.c index 05f9dc42c0..7f0440970e 100644 --- a/yarp/api_pack.c +++ b/yarp/api_pack.c @@ -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)); } |
