[#50466] [ruby-trunk - Bug #7492][Open] Segmentation fault at DL::TestDL#test_call_double on x64 Windows 8 — "phasis68 (Heesob Park)" <phasis@...>

23 messages 2012/12/02

[#50558] [ruby-trunk - Feature #7511][Open] short-circuiting logical implication operator — "rits (First Last)" <redmine@...>

12 messages 2012/12/04

[#50575] [ruby-trunk - Feature #7517][Open] Fixnum::MIN,MAX — "matz (Yukihiro Matsumoto)" <matz@...>

20 messages 2012/12/05

[#50755] Becoming a committer — Charlie Somerville <charlie@...>

Hi ruby-core,

21 messages 2012/12/11
[#50759] Re: Becoming a committer — Yukihiro Matsumoto <matz@...> 2012/12/11

Hi,

[#50784] Re: Becoming a committer — Charles Oliver Nutter <headius@...> 2012/12/11

It's really this easy? If so, I'll send over my public key today :)

[#50795] Re: Becoming a committer — Yukihiro Matsumoto <matz@...> 2012/12/11

Hi,

[#50806] [ruby-trunk - Feature #7548][Open] Load and Require Callbacks — "trans (Thomas Sawyer)" <transfire@...>

12 messages 2012/12/12

[#50810] [ruby-trunk - Feature #7549][Open] A Ruby Design Process — "brixen (Brian Ford)" <brixen@...>

34 messages 2012/12/12

[#50867] [ruby-trunk - Bug #7556][Assigned] test error on refinement — "usa (Usaku NAKAMURA)" <usa@...>

14 messages 2012/12/13

[#50900] [ruby-trunk - Bug #7564][Open] r38175 introduces incompatibility — "tenderlovemaking (Aaron Patterson)" <aaron@...>

14 messages 2012/12/14

[#50951] [ruby-trunk - Bug #7584][Open] Ruby hangs when shutting down an ssl connection in gc finalization — "bpot (Bob Potter)" <bobby.potter@...>

12 messages 2012/12/17

[#51076] [ruby-trunk - Feature #7604][Open] Make === comparison operator ability to delegate comparison to an argument — "prijutme4ty (Ilya Vorontsov)" <prijutme4ty@...>

12 messages 2012/12/22

[ruby-core:51205] [ruby-trunk - Bug #7371] Fix undefined overflow checking in bigdecimal

From: "xi (Xi Wang)" <redmine@...>
Date: 2012-12-31 05:01:43 UTC
List: ruby-core #51205
Issue #7371 has been updated by xi (Xi Wang).


To see how it works, try to compile the following (simplified) code with gcc 4.8.  The entire function will be optimized away with "gcc -O2" (just grep "bar" in the resulting assembly code); gcc 4.7 or earlier doesn't do that.

#define SIGNED_VALUE    long
#define BASE_FIG        9

void bar(void);

static void AddExponent(SIGNED_VALUE e, SIGNED_VALUE n)
{
    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<eb) goto overflow;
        }
    }
    return;
overflow:
    bar();
}

void foo(SIGNED_VALUE e)
{
    AddExponent(e, 1);
}
----------------------------------------
Bug #7371: Fix undefined overflow checking in bigdecimal
https://bugs.ruby-lang.org/issues/7371#change-35165

Author: xi (Xi Wang)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: ext
Target version: 
ruby -v: 1.9.x


In AddExponent() at ext/bigdecimal/bigdecimal.c:3677, the overflow checks rely on signed integer overflow, which is undefined behavior in C.

    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<eb) goto overflow;
        }

Some compilers (e.g., gcc 4.8) will optimize away such overflow checks due to undefined behavior.  Ruby currently uses "-fno-strict-overflow" to disable such offending optimizations in gcc, but this workaround option is not supported by other compilers, thus not portable.

The attached patch uses unsigned multiplication for overflow checking, which is well defined in C.


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

In This Thread