Bug #57476 my_time.c compiler warnings about uninitialized use
Submitted: 15 Oct 2010 8:18 Modified: 28 Oct 2010 18:44
Reporter: Magnus Blåudd Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1.53, 5.1-bzr OS:Any
Assigned to: CPU Architecture:Any

[15 Oct 2010 8:18] Magnus Blåudd
Description:
sql/my_time.c: 831
	‘my_time.time_type’ is used uninitialized in this function
sql/my_time.c: 831
	‘my_time.neg’ is used uninitialized in this function
sql/my_time.c: 831
	‘my_time.second_part’ is used uninitialized in this function
libmysqld/my_time.c: 831
	‘my_time.time_type’ is used uninitialized in this function
libmysqld/my_time.c: 831
	‘my_time.neg’ is used uninitialized in this function
libmysqld/my_time.c: 831
	‘my_time.second_part’ is used uninitialized in this function

How to repeat:
Compile MySQL Server with "gcc (GCC) 4.4.2 20091027 (Red Hat 4.4.2-7)" using 
CFLAGS="-O3 -Wall -g -fno-omit-frame-pointer" CXXFLAGS="-O3 -Wall -g -fno-omit-frame-pointer" ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --libexecdir=/usr/local/mysql/bin  --with-extra-charsets=all --enable-thread-safe-client --enable-local-infile --with-zlib-dir=bundled --with-big-tables --with-readline --with-archive-storage-engine --with-plugins=max --with-embedded-server

Suggested fix:
=== modified file 'sql-common/my_time.c'
--- a/sql-common/my_time.c	2010-10-06 10:06:47 +0000
+++ b/sql-common/my_time.c	2010-10-14 16:22:13 +0000
@@ -730,6 +730,9 @@ void my_init_time(void)
   my_time.hour=		(uint) l_time->tm_hour;
   my_time.minute=	(uint) l_time->tm_min;
   my_time.second=	(uint) l_time->tm_sec;
+  my_time.second_part= 0;
+  my_time.neg= FALSE;
+  my_time.time_type= MYSQL_TIMESTAMP_DATETIME;
   my_system_gmt_sec(&my_time, &my_time_zone, &not_used); /* Init my_time_zone */
 }
[20 Oct 2010 8:16] Magnus Blåudd
Also seen with "gcc version 4.4.3 (Gentoo 4.4.3-r2 p1.2)"
[20 Oct 2010 18:52] Sveta Smirnova
Thank you for the feedback.

Verified as described.
[28 Oct 2010 18:44] Konstantin Osipov
Since we compile with -Werror now, I presume this is fixed already.
Otherwise, just make the change, you don't have to file a bug report (or even solicit a review for that matter) to fix a compiler warning.