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

ruby-changes:21665

From: kosaki <ko1@a...>
Date: Sat, 12 Nov 2011 11:12:29 +0900 (JST)
Subject: [ruby-changes:21665] kosaki:r33714 (trunk): * io.c (setup_narg): fix off by one bug.

kosaki	2011-11-12 11:12:19 +0900 (Sat, 12 Nov 2011)

  New Revision: 33714

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33714

  Log:
    * io.c (setup_narg): fix off by one bug.

  Modified files:
    trunk/ChangeLog
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33713)
+++ ChangeLog	(revision 33714)
@@ -1,3 +1,7 @@
+Sat Nov 12 10:59:49 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* io.c (setup_narg): fix off by one bug.
+
 Sat Nov 12 10:56:43 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* io.c (+setup_narg): factor out length calculation logic.
Index: io.c
===================================================================
--- io.c	(revision 33713)
+++ io.c	(revision 33714)
@@ -7959,13 +7959,12 @@
 		len = 256;
 	    rb_str_modify(arg);
 
-	    if (len <= RSTRING_LEN(arg)) {
-		len = RSTRING_LEN(arg);
-	    }
-	    if (RSTRING_LEN(arg) < len) {
+	    /* expand for data + sentinel. */
+	    if (RSTRING_LEN(arg) < len+1) {
 		rb_str_resize(arg, len+1);
 	    }
-	    RSTRING_PTR(arg)[len] = 17;	/* a little sanity check here */
+	    /* a little sanity check here */
+	    RSTRING_PTR(arg)[RSTRING_LEN(arg) - 1] = 17;
 	    narg = (long)(SIGNED_VALUE)RSTRING_PTR(arg);
 	}
     }

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

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