From: "shyouhei (Shyouhei Urabe)" Date: 2012-07-15T20:04:06+09:00 Subject: [ruby-core:46488] [ruby-trunk - Bug #6736] Avoid misoptimization due to division by zero Issue #6736 has been updated by shyouhei (Shyouhei Urabe). The patch seems OK to me. ---------------------------------------- Bug #6736: Avoid misoptimization due to division by zero https://bugs.ruby-lang.org/issues/6736#change-28126 Author: xi (Xi Wang) Status: Open Priority: Normal Assignee: Category: core Target version: 2.0.0 ruby -v: trunk In time.c (quo) we have: if (b == 0) rb_num_zerodiv(); c = a / b; This code pattern is dangerous. Some C compilers may move the division _before_ the check because: 1) It appears to the compiler that the division a / b is always reachable even with b == 0 (though rb_num_zerodiv invokes rb_raise internally). 2) Division by zero is undefined behavior. This happened to PostgreSQL before. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=616180 Attached patch marks rb_num_zerodiv as NORETURN to avoid this issue. -- http://bugs.ruby-lang.org/