Bug #51289 double Item_cache_decimal::val_real() is broken
Submitted: 18 Feb 2010 17:58 Modified: 20 Jun 2010 22:49
Reporter: Mark Callaghan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Davi Arnaut
Tags: Broken
Triage: Triaged: D4 (Minor)

[18 Feb 2010 17:58] Mark Callaghan
Description:
Functions with a return type of double should not return NULL.

double Item_cache_decimal::val_real()
{
  DBUG_ASSERT(fixed);
  double res;
  if (!value_cached && !cache_value())
    return NULL;
  my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
  return res;
}

gcc warns:
item.cc: In member function ‘virtual double Item_cache_decimal::val_real()’:
item.cc:7422: warning: converting to non-pointer type ‘double’ from NULL

bzr blame has this:

1700.191.1   hf@deer.                            20050209 | }
                                                          | 
                                                          | double Item_cache_decimal::val_real()
                                                          | {
                                                          |   DBUG_ASSERT(fixed);
                                                          |   double res;
2661.470.1   epotemkin@mysql.com                 20091124 |   if (!value_cached && !cache_value())
                                                          |     return NULL;
1700.191.1   hf@deer.                            20050209 |   my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
                                                          |   return res;
                                                          | }

How to repeat:
read sql/item.cc in mysql-next-mr branch in launchpad

Suggested fix:
don't ignore compiler warnings
compile with -Werror for gcc
[18 Feb 2010 22:00] Mark Callaghan
This is also in the 5.1.44 GA release
[19 Feb 2010 13:26] Susanne Ebrecht
Also true in actual 5.1 bzr main tree (revision 3360)

Verified as described by source code analysis.
[15 Mar 2010 12:08] 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/103215

3400 Davi Arnaut	2010-03-15
      Bug#51289: double Item_cache_decimal::val_real() is broken
      
      Fix up function return value, it must return a double.
[15 Mar 2010 12:11] Davi Arnaut
Queued to mysql-5.1-bugteam
[26 Mar 2010 8:22] Bugs System
Pushed into 5.5.4-m3 (revid:alik@sun.com-20100326080914-2pz8ns984e0spu03) (version source revid:alexey.kopytov@sun.com-20100320202342-3oapaq7r0t6qhexq) (merge vers: 5.5.3-m2) (pib:16)
[26 Mar 2010 8:26] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100326081116-m3v4l34yhr43mtsv) (version source revid:alik@sun.com-20100325072612-4sds00ix8ajo1e84) (pib:16)
[26 Mar 2010 8:30] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100326081944-qja07qklw1p2w7jb) (version source revid:alik@sun.com-20100325073410-4t4i9gu2u1pge7xb) (merge vers: 6.0.14-alpha) (pib:16)
[6 Apr 2010 7:57] Bugs System
Pushed into 5.1.46 (revid:sergey.glukhov@sun.com-20100405111026-7kz1p8qlzglqgfmu) (version source revid:davi.arnaut@sun.com-20100315120716-9u53xvihg1pbr4v2) (merge vers: 5.1.46) (pib:16)
[6 Apr 2010 12:55] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html
[17 Jun 2010 11:47] Bugs System
Pushed into 5.1.47-ndb-7.0.16 (revid:martin.skold@mysql.com-20100617114014-bva0dy24yyd67697) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[17 Jun 2010 12:24] Bugs System
Pushed into 5.1.47-ndb-6.2.19 (revid:martin.skold@mysql.com-20100617115448-idrbic6gbki37h1c) (version source revid:martin.skold@mysql.com-20100609211156-tsac5qhw951miwtt) (merge vers: 5.1.46-ndb-6.2.19) (pib:16)
[17 Jun 2010 13:11] Bugs System
Pushed into 5.1.47-ndb-6.3.35 (revid:martin.skold@mysql.com-20100617114611-61aqbb52j752y116) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)