Bug #45611 Minor code cleanup
Submitted: 19 Jun 2009 11:42 Modified: 14 Sep 2009 19:40
Reporter: Michal Hrusecky Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.1.35 OS:Linux
Assigned to: Davi Arnaut CPU Architecture:Any
Tags: Contribution

[19 Jun 2009 11:42] Michal Hrusecky
During compilation, gcc outputs some warning, I'll attach patch which fixes two of them.

First one is correcting obviously weird construction without any meaning.
Second one is a little correction preventing possible buffer overflow.

Found in 5.1.34, same thing applies for 5.1.35

How to repeat:
Try to compile and watchout for gcc warnings which looks serious.

Suggested fix:
Will follow
[19 Jun 2009 11:43] Michal Hrusecky
Patch to fix mentioned issues

Attachment: mysql-5.1.34-code-cleanup.patch (text/x-patch), 1.37 KiB.

[20 Jun 2009 5:56] Sveta Smirnova
Thank you for the report.

Which warnings do you get and which version of gcc do you use?
[23 Jun 2009 12:59] Michal Hrusecky
gcc version:
gcc (SUSE Linux) 4.4.0 [gcc-4_4-branch revision 148163]


For the first most obvious error:

../../../../../../storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp:7525: warning: operation on 'old_ptr_p' may be undefined

For the second less obvious one:

g++ -DHAVE_CONFIG_H -DNDEBUG -DDEFAULT_MYSQL_HOME="\"/usr\"" -DDATADIR="\"/var/lib/mysql\"" -DSHAREDIR="\"/usr/share/mysql\"" -DMYSQLCLUSTERDIR="\".\""  -I. -I../../../../../storage/ndb/src/mgmsrv -I../../../../include -I../../../../../storage/ndb/src/ndbapi -I../../../../../storage/ndb/src/mgmapi -I../../../../../storage/ndb/src/common/mgmcommon -I../../../../../storage/ndb/src/mgmclient -I../../../../../storage/ndb/src/mgmsrv -I../../../../include -I../../../../storage/ndb/include -I../../../../../include -I../../../../../mysys -I../../../../../storage/ndb/include -I../../../../../storage/ndb/include/kernel -I../../../../../storage/ndb/include/transporter -I../../../../../storage/ndb/include/debugger -I../../../../../storage/ndb/include/mgmapi -I../../../../../storage/ndb/include/mgmcommon -I../../../../../storage/ndb/include/ndbapi -I../../../../../storage/ndb/include/util -I../../../../../storage/ndb/include/portlib -I../../../../../storage/ndb/include/logger      -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DPIC -fPIC -DUNDEF_HAVE_INITGROUPS -DFORCE_INIT_OF_VARS -fno-strict-aliasing -fno-exceptions -fno-rtti   -fno-implicit-templates -fno-exceptions -fno-rtti -MT InitConfigFileParser.o -MD -MP -MF .deps/InitConfigFileParser.Tpo -c -o InitConfigFileParser.o ../../../../../storage/ndb/src/mgmsrv/InitConfigFileParser.cpp
In file included from /usr/include/string.h:640,
                 from ../../../../../include/m_string.h:30,
                 from ../../../../storage/ndb/include/ndb_global.h:58,
                 from ../../../../../storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:16:
In function 'char* strncat(char*, const char*, size_t)',
    inlined from 'Config* InitConfigFileParser::run_config_rules(InitConfigFileParser::Context&)' at ../../../../../storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:212:
/usr/include/bits/string3.h:153: warning: call to char* __builtin___strncat_chk(char*, const char*, long unsigned int, long unsigned int) might overflow destination buffer
[24 Jun 2009 6:47] Sveta Smirnova
Thank you for the feedback.

Bug is still not repeatable for me. Which configure options do you use? Please also try version 5.1.36 to see if problem solved.
[25 Jun 2009 14:38] Michal Hrusecky
5.1.36 is not released yet (or at least it is not available on download page).
It's warning only and I'm still able to compile MySQL, but it points out to
some more or less problematic pieces of code. And possible problems should be
obvious from attached patch. My compile options were following...

$ export 'CFLAGS=-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DPIC -fPIC -DUNDEF_HAVE_INITGROUPS -DFORCE_INIT_OF_VARS -fno-strict-aliasing'
$ CFLAGS='-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DPIC -fPIC -DUNDEF_HAVE_INITGROUPS -DFORCE_INIT_OF_VARS -fno-strict-aliasing'
$ export 'CXXFLAGS=-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DPIC -fPIC -DUNDEF_HAVE_INITGROUPS -DFORCE_INIT_OF_VARS -fno-strict-aliasing -fno-exceptions -fno-rtti'
$ CXXFLAGS='-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DPIC -fPIC -DUNDEF_HAVE_INITGROUPS -DFORCE_INIT_OF_VARS -fno-strict-aliasing -fno-exceptions -fno-rtti'
$ ../configure --enable-assembler --without-readline --infodir=/usr/share/info --libdir=/usr/lib64 --libexecdir=/usr/sbin --localstatedir=/var/lib/mysql --mandir=/usr/share/man --prefix=/usr --sysconfdir=/etc --with-mysqld-user=mysql --with-mysqld-group=mysql --without-debug --datadir=/usr/share --includedir=/usr/include --with-charset=utf8 --with-collation=utf8_unicode_ci --with-extra-charsets=complex --with-unix-socket-path=/var/run/mysql/mysql.sock --enable-thread-safe-client '--with-comment=SUSE MySQL RPM' --with-libwrap --with-server-suffix= --with-ssl=/usr --with-plugins=partition,csv,heap,myisam,ndbcluster,innobase 'HOSTNAME=/bin/hostname -f' --with-embedded-server
[30 Jul 2009 12:55] Susanne Ebrecht
Many thanks for writing a bug report.

GCC 4.4 is not stable at the moment.

Do you have same issues by using GCC 4.3?
[31 Jul 2009 15:59] Lenz Grimmer
Susanne, why do you think that gcc 4.4 is "not stable"?
It has been officially released from http://gcc.gnu.org/

And as you can see, it's already used to compile the openSUSE Linux Distribution (Michal is the maintainer of the MySQL package on this distribution). So please reconsider setting the status of this bug to "verified" - it's a valuable contribution.

Michal, thank you for your patch, it's appreciated! Please keep them coming.
[1 Aug 2009 7:21] Sveta Smirnova

I was not able to repeat the problem. If this is repeatable for you set to "Verified" yourself, otherwise it should be open.
[30 Aug 2009 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[31 Aug 2009 9:39] Sveta Smirnova
Thank you for the feedback.

We are still not able to repeat the problem. Does it exist in version 5.1.37 in your environment?
[1 Sep 2009 12:29] 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:


3095 Davi Arnaut	2009-09-01
      Bug#45611: Minor code cleanup
      Remove a self assignment.
      Rework a few constructs to avoid a potential overflow.
      Based upon patch contributed by Michal Hrusecky
     @ storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
        Remove self assignment, the object is being initialized.
     @ storage/ndb/src/mgmsrv/InitConfigFileParser.cpp
        Setup the string in a single snprintf.
[1 Sep 2009 12:33] Davi Arnaut
Queued to 5.1-bugteam
[2 Sep 2009 16:42] Bugs System
Pushed into 5.1.39 (revid:joro@sun.com-20090902154533-8actmfcsjfqovgsb) (version source revid:mattias.jonsson@sun.com-20090901135459-9v1p87eto9vxqq2s) (merge vers: 5.1.39) (pib:11)
[4 Sep 2009 1:20] Paul DuBois
No changelog entry needed.

Setting report to NDI pending push into 5.4.x.
[14 Sep 2009 16:04] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090914155317-m1g9wodmndzdj4l1) (version source revid:alik@sun.com-20090914155317-m1g9wodmndzdj4l1) (merge vers: 5.4.4-alpha) (pib:11)
[14 Sep 2009 19:40] Paul DuBois
No changelog entry needed.
[1 Oct 2009 5:59] Bugs System
Pushed into 5.1.39-ndb-6.3.28 (revid:jonas@mysql.com-20091001055605-ap2kiaarr7p40mmv) (version source revid:jonas@mysql.com-20091001055605-ap2kiaarr7p40mmv) (merge vers: 5.1.39-ndb-6.3.28) (pib:11)
[1 Oct 2009 7:25] Bugs System
Pushed into 5.1.39-ndb-7.0.9 (revid:jonas@mysql.com-20091001072547-kv17uu06hfjhgjay) (version source revid:jonas@mysql.com-20091001071652-irejtnumzbpsbgk2) (merge vers: 5.1.39-ndb-7.0.9) (pib:11)
[1 Oct 2009 13:25] Bugs System
Pushed into 5.1.39-ndb-7.1.0 (revid:jonas@mysql.com-20091001123013-g9ob2tsyctpw6zs0) (version source revid:jonas@mysql.com-20091001123013-g9ob2tsyctpw6zs0) (merge vers: 5.1.39-ndb-7.1.0) (pib:11)
[5 Oct 2009 10:50] Bugs System
Pushed into 5.1.39-ndb-6.2.19 (revid:jonas@mysql.com-20091005103850-dwij2dojwpvf5hi6) (version source revid:jonas@mysql.com-20090930185117-bhud4ek1y0hsj1nv) (merge vers: 5.1.39-ndb-6.2.19) (pib:11)