summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-02-04 05:02:43 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-02-04 05:02:43 +0000
commit6449abf51ef98436da2e6b229447f2a9e0cae970 (patch)
treef20629839d412379b2df57e59cc0ff8a403c3d86 /array.c
parent01bb9da7acfeb868eeec4fc20061c57d85b26cf8 (diff)
segv on empty arrays
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@64 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/array.c b/array.c
index a0e1e00..6a6dce4 100644
--- a/array.c
+++ b/array.c
@@ -410,7 +410,7 @@ ary_indexes(ary, args)
VALUE new_ary;
int i = 0;
- if (!args || NIL_P(args)) {
+ if (!args || NIL_P(args) || RARRAY(args)->len == 0) {
return ary_new2(0);
}
@@ -683,6 +683,8 @@ ary_reverse(ary)
VALUE *p1, *p2;
VALUE tmp;
+ if (RARRAY(ary)->len == 0) return ary;
+
p1 = RARRAY(ary)->ptr;
p2 = p1 + RARRAY(ary)->len - 1; /* points last item */
@@ -734,6 +736,8 @@ VALUE
ary_sort_bang(ary)
VALUE ary;
{
+ if (RARRAY(ary)->len == 0) return ary;
+
ary_modify(ary);
qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), iterator_p()?sort_1:sort_2);
return ary;
@@ -743,6 +747,7 @@ VALUE
ary_sort(ary)
VALUE ary;
{
+ if (RARRAY(ary)->len == 0) return ary;
return ary_sort_bang(ary_clone(ary));
}