Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modify String#bytes.

It should return non-negative integer.
  • Loading branch information...
commit 72ae2150c74359210e3e842f861d1dd66be464b6 1 parent c02c264
Masamitsu MURASE masamitsu-murase authored
Showing with 5 additions and 2 deletions.
  1. +1 −1  src/string.c
  2. +4 −1 test/t/string.rb
2  src/string.c
View
@@ -2997,7 +2997,7 @@ mrb_str_bytes(mrb_state *mrb, mrb_value str)
{
struct RString *s = mrb_str_ptr(str);
mrb_value a = mrb_ary_new_capa(mrb, s->len);
- char *p = s->ptr, *pend = p + s->len;
+ unsigned char *p = (unsigned char *)(s->ptr), *pend = p + s->len;
while (p < pend) {
mrb_ary_push(mrb, a, mrb_fixnum_value(p[0]));
5 test/t/string.rb
View
@@ -369,7 +369,10 @@
str1 = "hello"
bytes1 = [104, 101, 108, 108, 111]
- str1.bytes == bytes1
+ str2 = "\xFF"
+ bytes2 = [0xFF]
+
+ str1.bytes == bytes1 and str2.bytes == bytes2
end
assert('String#each_byte') do
Please sign in to comment.
Something went wrong with that request. Please try again.