ruby-changes:56581
From: Nobuyoshi <ko1@a...>
Date: Wed, 17 Jul 2019 10:52:57 +0900 (JST)
Subject: [ruby-changes:56581] Nobuyoshi Nakada: ed2f2b4f98 (master): Named the backward compatible dump size
https://git.ruby-lang.org/ruby.git/commit/?id=ed2f2b4f98 From ed2f2b4f98800540024b9c4a5ebde98674889013 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 16 Jul 2019 22:39:39 +0900 Subject: Named the backward compatible dump size diff --git a/time.c b/time.c index fe1ef78..f7808c7 100644 --- a/time.c +++ b/time.c @@ -5008,13 +5008,15 @@ time_strftime(VALUE time, VALUE format) https://github.com/ruby/ruby/blob/trunk/time.c#L5008 int ruby_marshal_write_long(long x, char *buf); +enum {base_dump_size = 8}; + /* :nodoc: */ static VALUE time_mdump(VALUE time) { struct time_object *tobj; unsigned long p, s; - char buf[8]; + char buf[base_dump_size]; int i; VALUE str; @@ -5090,7 +5092,7 @@ time_mdump(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L5092 * binary (like as Fixnum and Bignum). */ size_t ysize = rb_absint_size(year_extend, NULL); - char *p, buf_year_extend[9]; + char *p, buf_year_extend[sizeof(long)+1]; if (ysize > LONG_MAX || (i = ruby_marshal_write_long((long)ysize, buf_year_extend)) < 0) { rb_raise(rb_eArgError, "year too %s to marshal: %"PRIsVALUE" UTC", @@ -5217,7 +5219,7 @@ time_mload(VALUE time, VALUE str) https://github.com/ruby/ruby/blob/trunk/time.c#L5219 StringValue(str); buf = (unsigned char *)RSTRING_PTR(str); - if (RSTRING_LEN(str) < 8) { + if (RSTRING_LEN(str) < base_dump_size) { invalid_format: rb_raise(rb_eTypeError, "marshaled time format differ"); } @@ -5245,11 +5247,11 @@ time_mload(VALUE time, VALUE str) https://github.com/ruby/ruby/blob/trunk/time.c#L5247 if (NIL_P(year)) { year = INT2FIX(((int)(p >> 14) & 0xffff) + 1900); } - if (RSTRING_LEN(str) > 8) { - long len = RSTRING_LEN(str) - 8; + if (RSTRING_LEN(str) > base_dump_size) { + long len = RSTRING_LEN(str) - base_dump_size; long ysize = 0; VALUE year_extend; - const char *ybuf = (const char *)(buf += 8); + const char *ybuf = (const char *)(buf += base_dump_size); ysize = ruby_marshal_read_long(&ybuf, len); len -= ybuf - (const char *)buf; if (ysize < 0 || ysize > len) goto invalid_format; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/