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

ruby-changes:41659

From: nobu <ko1@a...>
Date: Thu, 4 Feb 2016 14:10:40 +0900 (JST)
Subject: [ruby-changes:41659] nobu:r53733 (trunk): mask upper nibble

nobu	2016-02-04 14:10:36 +0900 (Thu, 04 Feb 2016)

  New Revision: 53733

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

  Log:
    mask upper nibble
    
    * ext/cgi/escape/escape.c (optimized_escape): move c and use it
      instead of cstr[i].  mask upper nibble for the platforms where
      CHAR_BIT > 8.  [Fix GH-1238]

  Modified files:
    trunk/ext/cgi/escape/escape.c
Index: ext/cgi/escape/escape.c
===================================================================
--- ext/cgi/escape/escape.c	(revision 53732)
+++ ext/cgi/escape/escape.c	(revision 53733)
@@ -106,8 +106,9 @@ optimized_escape(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L106
     len  = RSTRING_LEN(str);
     cstr = RSTRING_PTR(str);
 
-    for (i = 0; i < len; i++) {
-	if (!url_unreserved_char(cstr[i])) {
+    for (i = 0; i < len; ++i) {
+	const unsigned char c = (unsigned char)cstr[i];
+	if (!url_unreserved_char(c)) {
 	    if (!dest) {
 		dest = rb_str_buf_new(len);
 	    }
@@ -115,12 +116,11 @@ optimized_escape(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L116
 	    rb_str_cat(dest, cstr + beg, i - beg);
 	    beg = i + 1;
 
-	    if (cstr[i] == ' ') {
+	    if (c == ' ') {
 		rb_str_cat_cstr(dest, "+");
 	    }
 	    else {
-		unsigned char c = (unsigned char)cstr[i];
-		buf[1] = upper_hexdigits[c >> 4];
+		buf[1] = upper_hexdigits[(c >> 4) & 0xf];
 		buf[2] = upper_hexdigits[c & 0xf];
 		rb_str_cat(dest, buf, 3);
 	    }

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

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