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
5ed89a40
Commit
5ed89a40
authored
Jul 28, 2012
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #399 from akuroda/array_first_fix
fix segmentation fault in Array#first
parents
919a8477
a2aa7e7f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
src/array.c
src/array.c
+3
-0
test/t/array.rb
test/t/array.rb
+18
-1
No files found.
src/array.c
View file @
5ed89a40
...
@@ -764,6 +764,9 @@ mrb_ary_first(mrb_state *mrb, mrb_value self)
...
@@ -764,6 +764,9 @@ mrb_ary_first(mrb_state *mrb, mrb_value self)
if
(
mrb_get_args
(
mrb
,
"|i"
,
&
size
)
==
0
)
{
if
(
mrb_get_args
(
mrb
,
"|i"
,
&
size
)
==
0
)
{
return
(
a
->
len
>
0
)
?
a
->
ptr
[
0
]
:
mrb_nil_value
();
return
(
a
->
len
>
0
)
?
a
->
ptr
[
0
]
:
mrb_nil_value
();
}
}
if
(
size
<
0
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"negative array size"
);
}
if
(
size
>
a
->
len
)
size
=
a
->
len
;
if
(
size
>
a
->
len
)
size
=
a
->
len
;
if
(
a
->
flags
&
MRB_ARY_SHARED
)
{
if
(
a
->
flags
&
MRB_ARY_SHARED
)
{
...
...
test/t/array.rb
View file @
5ed89a40
...
@@ -118,7 +118,24 @@ assert('Array#first', '15.2.12.5.13') do
...
@@ -118,7 +118,24 @@ assert('Array#first', '15.2.12.5.13') do
a
=
[]
a
=
[]
b
=
[
1
,
2
,
3
]
b
=
[
1
,
2
,
3
]
a
.
first
==
nil
and
b
.
first
==
1
e2
=
nil
e3
=
nil
begin
# this will cause an exception due to the wrong argument
[
1
,
2
,
3
].
first
(
-
1
)
rescue
=>
e1
e2
=
e1
end
begin
# this will cause an exception due to the wrong argument
[
1
,
2
,
3
].
first
(
1
,
2
)
rescue
=>
e1
e3
=
e1
end
a
.
first
==
nil
and
b
.
first
==
1
and
b
.
first
(
0
)
==
[]
and
b
.
first
(
1
)
==
[
1
]
and
b
.
first
(
4
)
==
[
1
,
2
,
3
]
and
e2
.
class
==
ArgumentError
and
e3
.
class
==
ArgumentError
end
end
assert
(
'Array#index'
,
'15.2.12.5.14'
)
do
assert
(
'Array#index'
,
'15.2.12.5.14'
)
do
...
...
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