summaryrefslogtreecommitdiff
path: root/ext/cgi/escape/escape.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-04 05:10:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-04 05:10:36 +0000
commita320f811cfe126d978c9def412daf3c18108b5f3 (patch)
tree5b3a7809f4a8421cc1e4a8753f3f3d491416fc48 /ext/cgi/escape/escape.c
parent7d1dd7cad8b8773490240a1d0f4fd20f55de7644 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/cgi/escape/escape.c')
-rw-r--r--ext/cgi/escape/escape.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ext/cgi/escape/escape.c b/ext/cgi/escape/escape.c
index 6294183..cfa8026 100644
--- a/ext/cgi/escape/escape.c
+++ b/ext/cgi/escape/escape.c
@@ -106,8 +106,9 @@ optimized_escape(VALUE str)
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)
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);
}