Bug #59585 Fix 58912 introduces compiler warning due to potentially uninitialized variable
Submitted: 18 Jan 2011 14:12 Modified: 10 Feb 2011 19:57
Reporter: Bjørn Munch Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.1+, 5.5, 5.6.2 OS:Any
Assigned to: Marko Mäkelä CPU Architecture:Any
Tags: innodb, warning

[18 Jan 2011 14:12] Bjørn Munch
Description:
I'm unable to build using my default cmake setup on Linux, It fails thus:

------
cc1: warnings being treated as errors
/home/bm136801/my/main-tr/storage/innobase/row/row0upd.c: In function ‘row_upd_changes_ord_field_binary’:
/home/bm136801/my/main-tr/storage/innobase/row/row0upd.c:1225: warning: ‘dfield_len’ may be used uninitialized in this function
------

First use of this variable in the function is:

buf = row_ext_lookup(ext, col_no, &dfield_len);

How to repeat:
This apparently depends on compiler version and I don't know what else. Built on siv35.norway.sun.com

gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
[18 Jan 2011 14:14] Bjørn Munch
Adding a pointer to the referred bug: Bug #58912
[20 Jan 2011 11:35] Sveta Smirnova
Thank you for the report.

You wrote:

> I'm unable to build using my default cmake setup on Linux, It fails thus:

But mention 5.1 version. Please indicate accurate tree and cmake/configure options you experience problems with.
[20 Jan 2011 11:45] Bjørn Munch
I mention 5.1 because the offending code exists in 5.1 and so should be fixed there too.

I tried mysql-5.5:

CFLAGS="-g -O2 -Wall -Wno-strict-aliasing"
CXXFLAGS="-g -O2 -Wall -Wno-strict-aliasing -Wno-unused-parameter -fno-exceptions"

cmake $DIR -DWITH_DEBUG=ON -DWITH_SSL=yes

This was on RHAS 5.

In any case, the simple fix is probably to initialize the variable in question to 0. That worked for me.
[20 Jan 2011 12:13] Sveta Smirnova
Thank you for the feedback.

Verified as described in mysql-trunk.
[20 Jan 2011 23:06] Marko Mäkelä
I have encountered this too, with certain compilation flags. The warning is a bogus one, but we should silence it nevertheless.

The compiler cannot know that row_ext_lookup(ext, col_no, &dfield_len) is always going to initialize dfield_len when it returns non-NULL. I will implement the suggested fix of initializing dfield_len = 0 before the call.
[20 Jan 2011 23:13] Davi Arnaut
For what it's worth, we have the UNINIT_VAR macro which suppresses uninitialized variable warnings without generating code.
[25 Jan 2011 13:39] Marko Mäkelä
Davi, thanks for the hint. I tried the UNINIT_VAR, but it did not work in this case. Besides, it looks like UNINIT_VAR does always generate some code. My solution does too, but it should not be that bad, as updates of prefix-indexed off-page columns should be seldom anyway.
[25 Jan 2011 13:43] 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/129563
[25 Jan 2011 13:43] 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/129564
[30 Jan 2011 16:58] Bugs System
Pushed into mysql-5.1 5.1.56 (revid:vasil.dimov@oracle.com-20110130164158-1q99a41kb2wvkw3a) (version source revid:vasil.dimov@oracle.com-20110130164158-1q99a41kb2wvkw3a) (merge vers: 5.1.56) (pib:24)
[30 Jan 2011 16:59] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:vasil.dimov@oracle.com-20110130165639-1pr3opz839b98q5j) (version source revid:vasil.dimov@oracle.com-20110130165522-m0o6al0pn5ig9kv3) (merge vers: 5.6.2) (pib:24)
[30 Jan 2011 17:00] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:vasil.dimov@oracle.com-20110130165343-he9art47agq1a3gr) (version source revid:vasil.dimov@oracle.com-20110130165137-5lvzsq9j29j0hp1s) (merge vers: 5.5.10) (pib:24)