From ae23000c0e0e4f4af1b4462147d950549b3abdbe Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 19 Aug 2002 05:56:09 +0000 Subject: * 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 --- array.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'array.c') diff --git a/array.c b/array.c index 4d9de4bd60..69bafe643c 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); } -- cgit v1.2.3