From 359d53787821dc287d0411565801d54791f0a9c6 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 5 Aug 2010 09:25:39 +0000 Subject: [PATCH] * marshal.c (w_float): should not append a dot if no fractal part exists. [ruby-dev:41936] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ marshal.c | 4 ++-- test/ruby/test_marshal.rb | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47449e2bac..a30c14aa7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Aug 5 18:25:33 2010 Nobuyoshi Nakada + + * marshal.c (w_float): should not append a dot if no fractal part + exists. [ruby-dev:41936] + Thu Aug 5 17:11:43 2010 Yukihiro Matsumoto * parse.y (void_expr_gen): add 'possibly' to warning message. diff --git a/marshal.c b/marshal.c index bcbc2def83..d3f7002eb5 100644 --- a/marshal.c +++ b/marshal.c @@ -376,8 +376,8 @@ w_float(double d, struct dump_arg *arg) digs = (int)(e - p); if (decpt < -3 || decpt > digs) { buf[len++] = p[0]; - buf[len++] = '.'; - memcpy(buf + len, p + 1, --digs); + if (--digs > 0) buf[len++] = '.'; + memcpy(buf + len, p + 1, digs); len += digs; len += snprintf(buf + len, sizeof(buf) - len, "e%d", decpt - 1); } diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index d78183192c..f3d86277dd 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -40,6 +40,11 @@ class TestMarshal < Test::Unit::TestCase obj = (x.to_f + y.to_f / z.to_f) * Math.exp(w.to_f / (x.to_f + y.to_f / z.to_f)) assert_equal obj, Marshal.load(Marshal.dump(obj)) } + + bug3659 = '[ruby-dev:41936]' + [1.0, 10.0, 100.0, 110.0].each {|x| + assert_equal(x, Marshal.load(Marshal.dump(x)), bug3659) + } end StrClone = String.clone