* Avoid undefined behaviors found by gcc -fsanitize=undefined.

gcc (Debian 4.9.1-16) 4.9.1

* string.c (rb_str_sum): Avoid undefined behavior.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-10-17 09:49:28 +00:00
parent 1efb3c31b7
commit 0d4185f30e
3 changed files with 13 additions and 2 deletions

View file

@ -1584,6 +1584,8 @@ class TestString < Test::Unit::TestCase
assert_equal(16, n.sum(17))
n[0] = 2.chr
assert_not_equal(15, n.sum)
assert_equal(17, n.sum(0))
assert_equal(17, n.sum(-1))
end
def check_sum(str, bits=16)
@ -1598,7 +1600,7 @@ class TestString < Test::Unit::TestCase
assert_equal(294, "abc".sum)
check_sum("abc")
check_sum("\x80")
0.upto(70) {|bits|
-3.upto(70) {|bits|
check_sum("xyz", bits)
}
end