diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h index 7762ad237..d16be868f 100644 --- a/ext/openssl/ossl.h +++ b/ext/openssl/ossl.h @@ -102,11 +102,27 @@ void ossl_want_uninitialized(VALUE self, const rb_data_type_t *type); */ #ifndef HAVE_RB_LEN_T /* Ruby 4.1 */ typedef long rb_len_t; +typedef unsigned long rb_ulen_t; +#endif +#ifndef SIZEOF_RB_LEN_T # define SIZEOF_RB_LEN_T SIZEOF_LONG +#endif +#ifndef RB_LEN_MAX # define RB_LEN_MAX LONG_MAX +#endif +#ifndef PRIdLEN # define PRIdLEN "ld" +#endif +#ifndef FIX2LEN +# define FIX2LEN FIX2LONG +#endif +#ifndef NUM2LEN # define NUM2LEN NUM2LONG +#endif +#ifndef LEN2NUM # define LEN2NUM LONG2NUM +#endif +#ifndef HAVE_RB_LEN_T static inline long rb_len2long(rb_len_t n) { diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c index ff5d3a538..56d7e00d2 100644 --- a/ext/openssl/ossl_bn.c +++ b/ext/openssl/ossl_bn.c @@ -75,12 +75,12 @@ integer_to_bnptr(VALUE obj, BIGNUM *orig) BIGNUM *bn; if (FIXNUM_P(obj)) { - long i; - unsigned char bin[sizeof(long)]; - long n = FIX2LONG(obj); - unsigned long un = labs(n); + size_t i; + unsigned char bin[sizeof(rb_ulen_t)]; + rb_len_t n = FIX2LEN(obj); + rb_ulen_t un = n < 0 ? 0 - (rb_ulen_t)n : (rb_ulen_t)n; - for (i = sizeof(long) - 1; 0 <= i; i--) { + for (i = sizeof(bin); 0 < i--;) { bin[i] = un & 0xff; un >>= 8; }