Bug #42965 isinf() on 32bit x86 with gcc 4.3 can produce incorrect results for ROUND()

Submitted: 18 Feb 2009 11:27 Modified: 15 May 2009 1:54
Reporter: Stewart Smith Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Alexey Kopytov CPU Architecture:Any

[18 Feb 2009 11:27] Stewart Smith
Description:
In Drizzle, we were hit directly by this GCC bug (that I found):
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39228

Theoretically MySQL could be hit by the same problem, depending on how the code is compiled (and with what compiler).

How to repeat:
see gcc bug

Suggested fix:
The proposed patch for Drizzle is below (will add a comment about the gcc bug before committing. will paste final commit here). It would be in sql/item_func.cc in mysql

=== modified file 'drizzled/function/math/round.cc'
--- drizzled/function/math/round.cc	2008-12-16 06:21:46 +0000
+++ drizzled/function/math/round.cc	2009-02-18 09:59:40 +0000
@@ -111,14 +111,22 @@
     tmp2 is here to avoid return the value with 80 bit precision
     This will fix that the test round(0.1,1) = round(0.1,1) is true
   */
-  volatile double tmp2;
+  double tmp2;
 
   tmp=(abs_dec < array_elements(log_10) ?
        log_10[abs_dec] : pow(10.0,(double) abs_dec));
 
+  double value_times_tmp= value * tmp;
+
+  if(sizeof(double) < sizeof(double_t))
+  {
+    volatile double t= value_times_tmp;
+    value_times_tmp= t;
+  }
+
   if (dec_negative && isinf(tmp))
     tmp2= 0;
-  else if (!dec_negative && isinf(value * tmp))
+  else if (!dec_negative && isinf(value_times_tmp))
     tmp2= value;
   else if (truncate)
   {
[23 Mar 2009 9:14] Alexey Kopytov
No code in MySQL 5.0/5.1/6.0 is affected by the mentioned GCC bug, since all isinf() calls either are in C++ code, or do not use intermediate values as the argument.

But just to be on the safe side, I will add a configure check and a workaround in case isinf() is unreliable.
[24 Mar 2009 0:07] Stewart Smith
note that the drizzle code affected was being built by g++
[24 Mar 2009 7:36] Alexey Kopytov
Stewart, how could drizzle be affected by the GCC bug then, if g++ transforms isinf() to the __isinf() call which always produces correct results?
[24 Mar 2009 8:27] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/70137

2741 Alexey Kopytov	2009-03-24
      Fix for bug #42965: isinf() on 32bit x86 with gcc 4.3 can    
                          produce incorrect results for ROUND() 
      
      Added a workaround and a configure check to test whether 
      isinf() is affected by the GCC bug #39228. 
             
      Since no code in MySQL server is currently affected by that 
      bug, the patch is actually a safeguard for possible future 
      code modifications. No test cases or changelog entries are 
      needed. 
      modified:
        configure.in
        include/my_global.h
[25 Mar 2009 2:10] Stewart Smith
i did look at a later tree than when i originally worked on the bug, so perhaps we changed what we were building the file with.

you can always check the compiled code.
[5 May 2009 18:52] Bugs System
Pushed into 5.0.82 (revid:davi.arnaut@sun.com-20090505184158-dvmedh8n472y8np5) (version source revid:davi.arnaut@sun.com-20090505184158-dvmedh8n472y8np5) (merge vers: 5.0.82) (pib:6)
[5 May 2009 19:40] Bugs System
Pushed into 5.1.35 (revid:davi.arnaut@sun.com-20090505190206-9xmh7dlc6kom8exp) (version source revid:davi.arnaut@sun.com-20090505190206-9xmh7dlc6kom8exp) (merge vers: 5.1.35) (pib:6)
[6 May 2009 14:08] Bugs System
Pushed into 6.0.12-alpha (revid:svoj@sun.com-20090506125450-yokcmvqf2g7jhujq) (version source revid:horst@mysql.com-20090327184517-25eq077q2beocs6y) (merge vers: 6.0.11-alpha) (pib:6)
[15 May 2009 1:54] Paul DuBois
No user-visible effects. No changelog entry needed.
[15 Jun 2009 8:27] Bugs System
Pushed into 5.1.35-ndb-6.3.26 (revid:jonas@mysql.com-20090615074202-0r5r2jmi83tww6sf) (version source revid:jonas@mysql.com-20090615070837-9pccutgc7repvb4d) (merge vers: 5.1.35-ndb-6.3.26) (pib:6)
[15 Jun 2009 9:06] Bugs System
Pushed into 5.1.35-ndb-7.0.7 (revid:jonas@mysql.com-20090615074335-9hcltksp5cu5fucn) (version source revid:jonas@mysql.com-20090615072714-rmfkvrbbipd9r32c) (merge vers: 5.1.35-ndb-7.0.7) (pib:6)
[15 Jun 2009 9:47] Bugs System
Pushed into 5.1.35-ndb-6.2.19 (revid:jonas@mysql.com-20090615061520-sq7ds4yw299ggugm) (version source revid:jonas@mysql.com-20090615054654-ebgpz7elwu1xj36j) (merge vers: 5.1.35-ndb-6.2.19) (pib:6)

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.067 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.