aboutsummaryrefslogtreecommitdiffstats
path: root/marshal.c
diff options
context:
space:
mode:
Diffstat (limited to 'marshal.c')
-rw-r--r--marshal.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/marshal.c b/marshal.c
index d828043492..c45cd03067 100644
--- a/marshal.c
+++ b/marshal.c
@@ -35,8 +35,8 @@
#if SIZEOF_SHORT == SIZEOF_BDIGIT
#define SHORTLEN(x) (x)
#else
-static long
-shortlen(long len, BDIGIT *ds)
+static size_t
+shortlen(size_t len, BDIGIT *ds)
{
BDIGIT num;
int offset = 0;
@@ -774,11 +774,17 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
w_byte(TYPE_BIGNUM, arg);
{
char sign = BIGNUM_SIGN(obj) ? '+' : '-';
- long len = BIGNUM_LEN(obj);
+ size_t len = BIGNUM_LEN(obj);
+ size_t slen;
BDIGIT *d = BIGNUM_DIGITS(obj);
+ slen = SHORTLEN(len);
+ if (LONG_MAX < slen) {
+ rb_raise(rb_eTypeError, "too big Bignum can't be dumped");
+ }
+
w_byte(sign, arg);
- w_long(SHORTLEN(len), arg); /* w_short? */
+ w_long((long)slen, arg);
while (len--) {
#if SIZEOF_BDIGIT > SIZEOF_SHORT
BDIGIT num = *d;