Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
54921aa6
Commit
54921aa6
authored
Nov 25, 2016
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Nov 25, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3289 from bouk/setbyte-len
Read length after args in String#setbyte
parents
99f6de52
83005d83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletion
+14
-1
mrbgems/mruby-string-ext/src/string.c
mrbgems/mruby-string-ext/src/string.c
+2
-1
mrbgems/mruby-string-ext/test/string.rb
mrbgems/mruby-string-ext/test/string.rb
+12
-0
No files found.
mrbgems/mruby-string-ext/src/string.c
View file @
54921aa6
...
...
@@ -23,10 +23,11 @@ static mrb_value
mrb_str_setbyte
(
mrb_state
*
mrb
,
mrb_value
str
)
{
mrb_int
pos
,
byte
;
long
len
=
RSTRING_LEN
(
str
)
;
long
len
;
mrb_get_args
(
mrb
,
"ii"
,
&
pos
,
&
byte
);
len
=
RSTRING_LEN
(
str
);
if
(
pos
<
-
len
||
len
<=
pos
)
mrb_raisef
(
mrb
,
E_INDEX_ERROR
,
"index %S is out of array"
,
mrb_fixnum_value
(
pos
));
if
(
pos
<
0
)
...
...
mrbgems/mruby-string-ext/test/string.rb
View file @
54921aa6
...
...
@@ -30,6 +30,18 @@ assert('String#setbyte') do
assert_equal
(
"Hello"
,
str1
)
end
assert
(
"String#setbyte raises IndexError if arg conversion resizes String"
)
do
$s
=
"01234
\n
"
class
Tmp
def
to_i
$s
.
chomp!
''
95
end
end
tmp
=
Tmp
.
new
assert_raise
(
IndexError
)
{
$s
.
setbyte
(
5
,
tmp
)
}
end
assert
(
'String#byteslice'
)
do
str1
=
"hello"
assert_equal
(
"e"
,
str1
.
byteslice
(
1
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment