From f433be6d9c9ca7010d2c4368030a09a76bb3b98b Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 6 Oct 2004 15:15:12 +0000 Subject: * io.c (rb_io_s_sysopen): preserve path in the buffer allocated by ALLOCA_N() to prevent modification. [ruby-dev:24438] * io.c (rb_io_mode_flags): preserve append mode flag. [ruby-dev:24436] * io.c (rb_io_modenum_mode): do not use external output buffer. * string.c (rb_str_justify): differ pointer retrieval to prevent padding string modification. [ruby-dev:24434] * range.c (range_each_func): allow func to terminate loop by returning RANGE_EACH_BREAK. * range.c (member_i): use RANGE_EACH_BREAK. [ruby-talk:114959] * marshal.c (r_byte): retrieve pointer from string value for each time. [ruby-dev:24404] * marshal.c (r_bytes0): ditto. * enum.c (sort_by_i): re-entrance check added. [ruby-dev:24399] * io.c (io_read): should freeze all reading buffer. [ruby-dev:24400] * string.c (rb_str_sum): should use bignums when bits is greater than or equals to sizeof(long)*CHAR_BITS. [ruby-dev:24395] * eval.c (specific_eval): defer pointer retrieval to prevent unsafe sourcefile string modification. [ruby-dev:24382] * eval.c (specific_eval): defer pointer retrieval to prevent unsafe sourcefile string modification. [ruby-dev:24382] * string.c (rb_str_sum): wrong cast caused wrong result. [ruby-dev:24385] * enum.c (enum_sort_by): hide temporary array from ObjectSpace.each_object. [ruby-dev:24386] * string.c (rb_str_sum): check was done with false pointer. [ruby-dev:24383] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 8782e41bc2..d70ea21868 100644 --- a/string.c +++ b/string.c @@ -4380,35 +4380,35 @@ rb_str_sum(argc, argv, str) ptr = p = RSTRING(str)->ptr; len = RSTRING(str)->len; pend = p + len; - if (bits > sizeof(long)*CHAR_BIT) { - VALUE res = INT2FIX(0); - VALUE mod; - - mod = rb_funcall(INT2FIX(1), rb_intern("<<"), 1, INT2FIX(bits)); - mod = rb_funcall(mod, '-', 1, INT2FIX(1)); + if (bits >= sizeof(long)*CHAR_BIT) { + VALUE sum = INT2FIX(0); while (p < pend) { str_mod_check(str, ptr, len); - res = rb_funcall(res, '+', 1, INT2FIX((unsigned int)*p)); + sum = rb_funcall(sum, '+', 1, INT2FIX((unsigned char)*p)); p++; } - res = rb_funcall(res, '&', 1, mod); - return res; + if (bits != 0) { + VALUE mod; + + mod = rb_funcall(INT2FIX(1), rb_intern("<<"), 1, INT2FIX(bits)); + mod = rb_funcall(mod, '-', 1, INT2FIX(1)); + sum = rb_funcall(sum, '&', 1, mod); + } + return sum; } else { - unsigned int res = 0; - unsigned int mod = (1<len > 0) { - f = RSTRING(pad)->ptr; - flen = RSTRING(pad)->len; - } - } - } + rb_scan_args(argc, argv, "11", &w, &pad); width = NUM2LONG(w); if (width < 0 || RSTRING(str)->len >= width) return rb_str_dup(str); res = rb_str_new5(str, 0, width); + if (argc == 0) { + StringValue(pad); + if (RSTRING(pad)->len > 0) { + f = RSTRING(pad)->ptr; + flen = RSTRING(pad)->len; + } + } p = RSTRING(res)->ptr; if (jflag != 'l') { n = width - RSTRING(str)->len; -- cgit v1.2.3