summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-19 05:56:09 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-19 05:56:09 +0000
commitae23000c0e0e4f4af1b4462147d950549b3abdbe (patch)
tree15aff53955adad0d278851c21030857a07bd2f5f /array.c
parent71a202fc01c3284608f486dd8ebb95bc57203221 (diff)
* array.c (sort_2): *a - *b may overflow.
* array.c (ary_new): len*sizeof(VALUE) may be a positive value. * array.c (rb_ary_initialize): ditto. * object.c (rb_class_allocate_instance): move singleton class check from rb_obj_alloc(). * re.c (rb_reg_initialize): should not modify frozen Regexp. * ext/tcltklib/tcltklib.c (ip_init): allocation framework. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/array.c b/array.c
index 4d9de4b..69bafe6 100644
--- a/array.c
+++ b/array.c
@@ -110,7 +110,7 @@ ary_new(klass, len)
if (len < 0) {
rb_raise(rb_eArgError, "negative array size (or size too big)");
}
- if (len > 0 && len * sizeof(VALUE) <= 0) {
+ if (len > 0 && len * sizeof(VALUE) <= len) {
rb_raise(rb_eArgError, "array size too big");
}
if (len == 0) len++;
@@ -236,7 +236,7 @@ rb_ary_initialize(argc, argv, ary)
if (len < 0) {
rb_raise(rb_eArgError, "negative array size");
}
- if (len > 0 && len * sizeof(VALUE) <= 0) {
+ if (len > 0 && len * (long)sizeof(VALUE) <= len) {
rb_raise(rb_eArgError, "array size too big");
}
if (len > RARRAY(ary)->aux.capa) {
@@ -304,7 +304,7 @@ rb_ary_store(ary, idx, val)
new_capa = ARY_DEFAULT_SIZE;
}
new_capa += idx;
- if (new_capa > new_capa * (long)sizeof(VALUE)) {
+ if (new_capa * (long)sizeof(VALUE) <= new_capa) {
rb_raise(rb_eArgError, "index too big");
}
RARRAY(ary)->aux.capa = new_capa;
@@ -1085,19 +1085,22 @@ sort_1(a, b)
}
static int
-sort_2(a, b)
- VALUE *a, *b;
+sort_2(ap, bp)
+ VALUE *ap, *bp;
{
VALUE retval;
+ VALUE a = *ap, b = *ap;
- if (FIXNUM_P(*a) && FIXNUM_P(*b)) {
- return *a - *b;
+ if (FIXNUM_P(a) && FIXNUM_P(b)) {
+ if (a > b) return INT2FIX(1);
+ if (a < b) return INT2FIX(-1);
+ return INT2FIX(0);
}
- if (TYPE(*a) == T_STRING && TYPE(*b) == T_STRING) {
- return rb_str_cmp(*a, *b);
+ if (TYPE(a) == T_STRING && TYPE(b) == T_STRING) {
+ return rb_str_cmp(a, b);
}
- retval = rb_funcall(*a, id_cmp, 1, *b);
+ retval = rb_funcall(a, id_cmp, 1, b);
return rb_cmpint(retval);
}