Bug #69407 Build warnings with mysql
Submitted: 5 Jun 2013 17:09 Modified: 7 Jan 2014 15:26
Reporter: Raghavendra Prabhu Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.5 OS:Linux
Assigned to: Tor Didriksen CPU Architecture:Any

[5 Jun 2013 17:09] Raghavendra Prabhu
Description:
Getting following compiler warnings when building 5.5.31 on gcc 
4.8.0:

=========================================================================================

[ 12%] Building C object mysys/CMakeFiles/mysys.dir/mf_format.c.o
/dev/shm/mysql55/src/mysql-5.5.31/mysys/md5.c: In function ‘my_MD5Final’:
/dev/shm/mysql55/src/mysql-5.5.31/mysys/md5.c:179:24: warning: argument to ‘sizeof’ in ‘memset’ call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
   memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
                        ^
--
[ 19%] In file included from /dev/shm/mysql55/src/mysql-5.5.31/mysys/stacktrace.c:16:0:
/dev/shm/mysql55/src/mysql-5.5.31/mysys/stacktrace.c: In function ‘safe_print_str’:
/dev/shm/mysql55/src/mysql-5.5.31/include/my_global.h:394:18: warning: typedef ‘compile_time_assert’ locally defined but not used [-Wunused-local-typedefs]
     typedef char compile_time_assert[(X) ? 1 : -1];             \
                  ^
--
In file included from /dev/shm/mysql55/src/mysql-5.5.31/mysys/lf_alloc-pin.c:102:0:
/dev/shm/mysql55/src/mysql-5.5.31/mysys/lf_alloc-pin.c: In function ‘lf_pinbox_init’:
/dev/shm/mysql55/src/mysql-5.5.31/include/my_global.h:394:18: warning: typedef ‘compile_time_assert’ locally defined but not used [-Wunused-local-typedefs]
     typedef char compile_time_assert[(X) ? 1 : -1];             \
                  ^
--
In file included from /dev/shm/mysql55/src/mysql-5.5.31/mysys/my_atomic.c:16:0:
/dev/shm/mysql55/src/mysql-5.5.31/mysys/my_atomic.c: In function ‘my_atomic_initialize’:
/dev/shm/mysql55/src/mysql-5.5.31/include/my_global.h:394:18: warning: typedef ‘compile_time_assert’ locally defined but not used [-Wunused-local-typedefs]
     typedef char compile_time_assert[(X) ? 1 : -1];             \
                  ^
--
[ 25%] Building C object storage/myisam/CMakeFiles/myisam.dir/mi_checksum.c.o
/dev/shm/mysql55/src/mysql-5.5.31/storage/myisam/mi_checksum.c: In function ‘mi_checksum’:
/dev/shm/mysql55/src/mysql-5.5.31/storage/myisam/mi_checksum.c:37:13: warning: argument to ‘sizeof’ in ‘memcpy’ call is the same pointer type ‘char *’ as the destination; expected ‘char’ or an explicit length [-Wsizeof-pointer-memaccess]
       sizeof(char*));
             ^
--
[ 27%] Building C object storage/myisammrg/CMakeFiles/myisammrg_embedded.dir/myrg_range.c.o
/dev/shm/mysql55/src/mysql-5.5.31/storage/myisam/mi_checksum.c: In function ‘mi_checksum’:
/dev/shm/mysql55/src/mysql-5.5.31/storage/myisam/mi_checksum.c:37:13: warning: argument to ‘sizeof’ in ‘memcpy’ call is the same pointer type ‘char *’ as the destination; expected ‘char’ or an explicit length [-Wsizeof-pointer-memaccess]
       sizeof(char*));
             ^
--
............
.......................

=========================================================================================

Full log here: http://codepad.org/kv9e6VOi  of following types:
-Wunused-local-typedefs
-Wsizeof-pointer-memaccess

How to repeat:
Building with gcc 4.8.0

Suggested fix:
Look if any are false positives, if not, fix them.
[5 Jun 2013 23:09] MySQL Verification Team
Thank you for the bug report. Which OS version are you using?. I couldn't repeat compiling 5.5.32:

miguel@miguel:~$ gcc --version
gcc (Ubuntu 4.8.1-2ubuntu1~13.04) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

[ 19%] Building C object mysys/CMakeFiles/mysys.dir/md5.c.o
[ 19%] Building C object mysys/CMakeFiles/mysys.dir/mf_cache.c.o
[ 19%] Building C object mysys/CMakeFiles/mysys.dir/mf_dirname.c.o
[ 19%] Building C object mysys/CMakeFiles/mysys.dir/mf_fn_ext.c.o
[ 19%] Building C object mysys/CMakeFiles/mysys.dir/mf_format.c.o <<<<<<<<<<
[ 19%] Building C object mysys/CMakeFiles/mysys.dir/mf_getdate.c.o
[5 Jun 2013 23:15] MySQL Verification Team
I found however several warnings like:

/home/miguel/mysql-5.5.32/sql/field.cc: In member function ‘virtual int Field_blob::store(const char*, uint, CHARSET_INFO*)’:
/home/miguel/mysql-5.5.32/sql/field.cc:7383:48: warning: argument to ‘sizeof’ in ‘void* memmove(void*, const void*, size_t)’ call is the same pointer type ‘char*’ as the source; expected ‘char’ or an explicit length [-Wsizeof-pointer-memaccess]
       bmove(ptr+packlength,(char*) &from,sizeof(char*));

                                             ^
/home/miguel/mysql-5.5.32/sql/field.cc: In member function ‘virtual int Field_geom::store(const char*, uint, CHARSET_INFO*)’:
/home/miguel/mysql-5.5.32/sql/field.cc:7900:50: warning: argument to ‘sizeof’ in ‘void* memmove(void*, const void*, size_t)’ call is the same pointer type ‘char*’ as the source; expected ‘char’ or an explicit length [-Wsizeof-pointer-memaccess]
     bmove(ptr + packlength, (char*) &from, sizeof(char*));
                                                  ^
/home/miguel/mysql-5.5.32/include/m_string.h:55:45: note: in definition of macro ‘bmove’
 # define bmove(d, s, n)  memmove((d), (s), (n))
[24 Oct 2013 9:55] Laurynas Biveinis
The md5.c warnings were fixed in 5.5.32 as bug 69407.  They are still present on 5.1 (and bug 69407 is not fixed there):

md5.c: In function ‘my_MD5Final’:
md5.c:179:24: error: argument to ‘sizeof’ in ‘memset’ call is the same expression as the destination; did you mean to dereference it? [-Werror=sizeof-pointer-memaccess]
   memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
                        ^
[24 Oct 2013 13:36] Laurynas Biveinis
Other GCC 4.8.1 warnings on the current 5.1 trunk:

gcc -DHAVE_CONFIG_H -I. -I../../include -I../../include -I../../include -I../../regex -I../../sql -I.   -Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror -Wdeclaration-after-statement -g -DSAFE_MUTEX -DSAFEMALLOC -Wall -Wextra -Wunused -Wwrite-strings -mtune=native -DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS  -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC -DSAFE_MUTEX -DUNIV_DEBUG -D_FORTIFY_SOURCE=2 -fmessage-length=0 -g3   -DUNIV_LINUX -MT mi_key.o -MD -MP -MF .deps/mi_key.Tpo -c -o mi_key.o mi_key.c
mi_key.c: In function ‘_mi_put_key_in_record’:
mi_key.c:422:31: error: argument to ‘sizeof’ in ‘memcpy’ call is the same pointer type ‘char *’ as the source; expected ‘char’ or an explicit length [-Werror=sizeof-pointer-memaccess]
       (char*) &blob_ptr,sizeof(char*));
                               ^
cc1: all warnings being treated as errors
make[2]: *** [mi_key.o] Error 1

gcc -DHAVE_CONFIG_H -I. -I../../include -I../../include -I../../include -I../../regex -I../../sql -I.   -Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror -Wdeclaration-after-statement -g -DSAFE_MUTEX -DSAFEMALLOC -Wall -Wextra -Wunused -Wwrite-strings -mtune=native -DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS  -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC -DSAFE_MUTEX -DUNIV_DEBUG -D_FORTIFY_SOURCE=2 -fmessage-length=0 -g3   -DUNIV_LINUX -MT mi_checksum.o -MD -MP -MF .deps/mi_checksum.Tpo -c -o mi_checksum.o mi_checksum.c
mi_checksum.c: In function ‘mi_checksum’:
mi_checksum.c:37:13: error: argument to ‘sizeof’ in ‘memcpy’ call is the same pointer type ‘char *’ as the destination; expected ‘char’ or an explicit length [-Werror=sizeof-pointer-memaccess]
       sizeof(char*));
             ^
cc1: all warnings being treated as errors
make[2]: *** [mi_checksum.o] Error 1

gcc -DMYSQL_SERVER -DDEFAULT_MYSQL_HOME="\"/usr/local/mysql\"" -DMYSQL_DATADIR="\"/usr/local/mysql/var\"" -DSHAREDIR="\"/usr/local/mysql/share/mysql\"" -DPLUGINDIR="\"/usr/local/mysql/lib/mysql/plugin\"" -DHAVE_EVENT_SCHEDULER -DHAVE_CONFIG_H -I. -I../include -I../include -I../include -I../regex -I.    -Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror -Wno-unused-parameter -g -DSAFE_MUTEX -DSAFEMALLOC -Wall -Wextra -Wunused -Wwrite-strings -Wno-unused-parameter -Wnon-virtual-dtor -felide-constructors -fno-exceptions -fno-rtti -mtune=native -DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS  -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC -DSAFE_MUTEX -DUNIV_DEBUG -D_FORTIFY_SOURCE=2 -fmessage-length=0 -g3   -DYACC_HEXT_HH -fno-implicit-templates -fno-exceptions -fno-rtti -MT field.o -MD -MP -MF .deps/field.Tpo -c -o field.o field.cc

In file included from mysql_priv.h:38:0,
                 from field.cc:29:
field.cc: In member function ‘virtual int Field_blob::store(const char*, uint, CHARSET_INFO*)’:
field.cc:7704:48: error: argument to ‘sizeof’ in ‘void* memmove(void*, const void*, size_t)’ call is the same pointer type ‘char*’ as the source; expected ‘char’ or an explicit length [-Werror=sizeof-pointer-memaccess]
       bmove(ptr+packlength,(char*) &from,sizeof(char*));
                                                ^
../include/m_string.h:53:45: note: in definition of macro ‘bmove’
 # define bmove(d, s, n)  memmove((d), (s), (n))
                                             ^
field.cc: In member function ‘virtual int Field_geom::store(const char*, uint, CHARSET_INFO*)’:
field.cc:8359:50: error: argument to ‘sizeof’ in ‘void* memmove(void*, const void*, size_t)’ call is the same pointer type ‘char*’ as the source; expected ‘char’ or an explicit length [-Werror=sizeof-pointer-memaccess]
     bmove(ptr + packlength, (char*) &from, sizeof(char*));
                                                  ^
../include/m_string.h:53:45: note: in definition of macro ‘bmove’
 # define bmove(d, s, n)  memmove((d), (s), (n))
                                             ^
cc1plus: all warnings being treated as errors
make[3]: *** [field.o] Error 1
[25 Oct 2013 7:28] Laurynas Biveinis
I am sorry, I meant bug 68909 "In my_MD5Final in mysys/md5.c, ctx is not properly zeroed as intended", not bug 69407 itself two comments above.
[28 Oct 2013 9:46] Laurynas Biveinis
The 5.5 branch warnings have been fixed by 

5.5$ bzr log -r 4387
------------------------------------------------------------
revno: 4387
committer: Tor Didriksen <tor.didriksen@oracle.com>
branch nick: 5.5
timestamp: Fri 2013-06-14 10:52:23 +0200
message:
  Bug#16729109: FIX COMPILATION WARNINGS WITH GCC 4.8
  Backport to 5.5
  (external Bug#69407 Build warnings with mysql)

The status of this bug needs updating.
[7 Jan 2014 15:26] Ståle Deraas
Dup of http://bugs.mysql.com/69407 , which was fixed in 5.5.33
[8 Jan 2014 4:48] Laurynas Biveinis
69407 is this bug.  What would be the correct bug id of the duplicate?