ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:49411] [ruby-trunk - Bug #7371][Open] Fix undefined overflow checking in bigdecimal
@ 2012-11-16  8:24 xi (Xi Wang)
  2012-11-17  3:11 ` [ruby-core:49477] [ruby-trunk - Bug #7371] " mrkn (Kenta Murata)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: xi (Xi Wang) @ 2012-11-16  8:24 UTC (permalink / raw
  To: ruby-core


Issue #7371 has been reported by xi (Xi Wang).

----------------------------------------
Bug #7371: Fix undefined overflow checking in bigdecimal
https://bugs.ruby-lang.org/issues/7371

Author: xi (Xi Wang)
Status: Open
Priority: Normal
Assignee: 
Category: 
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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:49477] [ruby-trunk - Bug #7371] Fix undefined overflow checking in bigdecimal
  2012-11-16  8:24 [ruby-core:49411] [ruby-trunk - Bug #7371][Open] Fix undefined overflow checking in bigdecimal xi (Xi Wang)
@ 2012-11-17  3:11 ` mrkn (Kenta Murata)
  2012-12-21 13:17 ` [ruby-core:51037] [ruby-trunk - Bug #7371][Assigned] " usa (Usaku NAKAMURA)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mrkn (Kenta Murata) @ 2012-11-17  3:11 UTC (permalink / raw
  To: ruby-core


Issue #7371 has been updated by mrkn (Kenta Murata).

Category set to ext
Assignee set to mrkn (Kenta Murata)


----------------------------------------
Bug #7371: Fix undefined overflow checking in bigdecimal
https://bugs.ruby-lang.org/issues/7371#change-33009

Author: xi (Xi Wang)
Status: Open
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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:51037] [ruby-trunk - Bug #7371][Assigned] Fix undefined overflow checking in bigdecimal
  2012-11-16  8:24 [ruby-core:49411] [ruby-trunk - Bug #7371][Open] Fix undefined overflow checking in bigdecimal xi (Xi Wang)
  2012-11-17  3:11 ` [ruby-core:49477] [ruby-trunk - Bug #7371] " mrkn (Kenta Murata)
@ 2012-12-21 13:17 ` usa (Usaku NAKAMURA)
  2012-12-31  5:01 ` [ruby-core:51205] [ruby-trunk - Bug #7371] " xi (Xi Wang)
  2013-12-12 17:18 ` [ruby-core:59076] [ruby-trunk - Bug #7371][Closed] " mrkn (Kenta Murata)
  3 siblings, 0 replies; 5+ messages in thread
From: usa (Usaku NAKAMURA) @ 2012-12-21 13:17 UTC (permalink / raw
  To: ruby-core


Issue #7371 has been updated by usa (Usaku NAKAMURA).

Status changed from Open to Assigned


----------------------------------------
Bug #7371: Fix undefined overflow checking in bigdecimal
https://bugs.ruby-lang.org/issues/7371#change-34941

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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:51205] [ruby-trunk - Bug #7371] Fix undefined overflow checking in bigdecimal
  2012-11-16  8:24 [ruby-core:49411] [ruby-trunk - Bug #7371][Open] Fix undefined overflow checking in bigdecimal xi (Xi Wang)
  2012-11-17  3:11 ` [ruby-core:49477] [ruby-trunk - Bug #7371] " mrkn (Kenta Murata)
  2012-12-21 13:17 ` [ruby-core:51037] [ruby-trunk - Bug #7371][Assigned] " usa (Usaku NAKAMURA)
@ 2012-12-31  5:01 ` xi (Xi Wang)
  2013-12-12 17:18 ` [ruby-core:59076] [ruby-trunk - Bug #7371][Closed] " mrkn (Kenta Murata)
  3 siblings, 0 replies; 5+ messages in thread
From: xi (Xi Wang) @ 2012-12-31  5:01 UTC (permalink / raw
  To: ruby-core


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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:59076] [ruby-trunk - Bug #7371][Closed] Fix undefined overflow checking in bigdecimal
  2012-11-16  8:24 [ruby-core:49411] [ruby-trunk - Bug #7371][Open] Fix undefined overflow checking in bigdecimal xi (Xi Wang)
                   ` (2 preceding siblings ...)
  2012-12-31  5:01 ` [ruby-core:51205] [ruby-trunk - Bug #7371] " xi (Xi Wang)
@ 2013-12-12 17:18 ` mrkn (Kenta Murata)
  3 siblings, 0 replies; 5+ messages in thread
From: mrkn (Kenta Murata) @ 2013-12-12 17:18 UTC (permalink / raw
  To: ruby-core


Issue #7371 has been updated by mrkn (Kenta Murata).

Status changed from Assigned to Closed

I think this issue had been fixed by akr in r40214.
----------------------------------------
Bug #7371: Fix undefined overflow checking in bigdecimal
https://bugs.ruby-lang.org/issues/7371#change-43629

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


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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-12-12 17:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-16  8:24 [ruby-core:49411] [ruby-trunk - Bug #7371][Open] Fix undefined overflow checking in bigdecimal xi (Xi Wang)
2012-11-17  3:11 ` [ruby-core:49477] [ruby-trunk - Bug #7371] " mrkn (Kenta Murata)
2012-12-21 13:17 ` [ruby-core:51037] [ruby-trunk - Bug #7371][Assigned] " usa (Usaku NAKAMURA)
2012-12-31  5:01 ` [ruby-core:51205] [ruby-trunk - Bug #7371] " xi (Xi Wang)
2013-12-12 17:18 ` [ruby-core:59076] [ruby-trunk - Bug #7371][Closed] " mrkn (Kenta Murata)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).