From: "xi (Xi Wang)" Date: 2012-07-15T18:54:40+09:00 Subject: [ruby-core:46486] [ruby-trunk - Bug #6736][Open] Avoid misoptimization due to division by zero Issue #6736 has been reported by xi (Xi Wang). ---------------------------------------- Bug #6736: Avoid misoptimization due to division by zero https://bugs.ruby-lang.org/issues/6736 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/