ruby/ruby — pull request #214 by xiw (2012-11-16 08:45:21+00:00)
Title: bigdecimal.c: avoid undefined overflow checking

http://bugs.ruby-lang.org/issues/7371

Compilers may optimize away the overflow/underflow checks since signed integer overflow is undefined behavior in C. This patch uses unsigned multiplications instead.

One can compile the code using `gcc -ftrapv` and should notice traps at run time.

One can also try to compile the following (simplified) code using gcc 4.8 with `gcc -S -O`; the resulting assembly code is an _empty_ function.

```
#define SIGNED_VALUE long
#define BASE_FIG 9

void bar(void);

void AddExponent(SIGNED_VALUE e, SIGNED_VALUE n)
{
n = 1;
SIGNED_VALUE m = e+n;
SIGNED_VALUE eb, mb;
if(e>0) {
if(n>0) {
mb = m*(SIGNED_VALUE)BASE_FIG;
eb = e*(SIGNED_VALUE)BASE_FIG;
if(mb