[前][次][番号順一覧][スレッド一覧]

ruby-changes:42018

From: nobu <ko1@a...>
Date: Sun, 13 Mar 2016 09:16:27 +0900 (JST)
Subject: [ruby-changes:42018] nobu:r54092 (trunk): numeric.c: fix edge case

nobu	2016-03-13 09:15:48 +0900 (Sun, 13 Mar 2016)

  New Revision: 54092

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54092

  Log:
    numeric.c: fix edge case
    
    * numeric.c (rb_fix2str): fix edge case, accidentally generated
      wrong Fixnum from LONG_MIN.

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
Index: numeric.c
===================================================================
--- numeric.c	(revision 54091)
+++ numeric.c	(revision 54092)
@@ -2905,7 +2905,15 @@ rb_fix2str(VALUE x, int base) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2905
 	return rb_usascii_str_new2("0");
     }
     if (val < 0) {
-	val = -val;
+	if (val == LONG_MIN) {
+	    int last = ((int)((val = LONG_MAX) % base) + 1);
+	    *--b = ruby_digitmap[last % base];
+	    val /= base;
+	    val += last == base; /* carry */
+	}
+	else {
+	    val = -val;
+	}
 	neg = 1;
     }
     do {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54091)
+++ ChangeLog	(revision 54092)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Mar 13 09:15:45 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (rb_fix2str): fix edge case, accidentally generated
+	  wrong Fixnum from LONG_MIN.
+
 Sat Mar 12 09:50:27 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_eval.c (rb_f_catch): [DOC] fix malformed RDoc syntax, "+...+"

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]