Bug #57588 Compiler warning in InnoDB due to comparison between signed and unsigned
Submitted: 19 Oct 2010 23:24 Modified: 9 Dec 2010 22:42
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.5+ OS:Linux
Assigned to: Sunny Bains CPU Architecture:Any

[19 Oct 2010 23:24] Davi Arnaut
Description:
/export/home/pb2/build/sb_0-2420828-1287525950.29/mysql-5.6.1-m4/storage/innobase/handler/handler0alter.cc: In function 'void innobase_col_to_mysql(const dict_col_t*, const uchar*, ulint, Field*)':
/export/home/pb2/build/sb_0-2420828-1287525950.29/mysql-5.6.1-m4/storage/innobase/handler/handler0alter.cc:103: warning: comparison between signed and unsigned integer expressions
/export/home/pb2/build/sb_0-2420828-1287525950.29/mysql-5.6.1-m4/storage/innobase/handler/handler0alter.cc:105: warning: comparison between signed and unsigned integer expressions

How to repeat:
See http://pb2.norway.sun.com/web.py?action=archive_download&archive_id=2422281&pretty=please
[19 Oct 2010 23:25] Davi Arnaut
Could be a false positive, haven't investigated. GCC version might be a bit old.
[19 Oct 2010 23:31] Davi Arnaut
Looks like it could be due to UNIV_EXPECT:

#define DATA_MBMINLEN(mbminmaxlen) UNIV_EXPECT(((mbminmaxlen) % DATA_MBMAX), 1)

# define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)

From GCC manual:

— Built-in Function: long __builtin_expect (long exp, long c)
[19 Oct 2010 23:49] Sunny Bains
As discussed on IRC, I think this should fix it:

=== modified file 'storage/innobase/include/data0type.h'
--- storage/innobase/include/data0type.h	revid:marko.makela@oracle.com-20101019064438-gfls1n6fign1brrh
+++ storage/innobase/include/data0type.h	2010-10-19 23:45:23 +0000
@@ -174,8 +174,11 @@
 /* Pack mbminlen, mbmaxlen to mbminmaxlen. */
 #define DATA_MBMINMAXLEN(mbminlen, mbmaxlen)	\
 	((mbmaxlen) * DATA_MBMAX + (mbminlen))
-/* Get mbminlen from mbminmaxlen. */
-#define DATA_MBMINLEN(mbminmaxlen) UNIV_EXPECT(((mbminmaxlen) % DATA_MBMAX), 1)
+/* Get mbminlen from mbminmaxlen. Cast the result of UNIV_EXPECT to ulint
+because in GCC it returns a long. */
+#define DATA_MBMINLEN(mbminmaxlen) ((ulint) \
+                                    UNIV_EXPECT(((mbminmaxlen) % DATA_MBMAX), \
+                                                1))
 /* Get mbmaxlen from mbminmaxlen. */
 #define DATA_MBMAXLEN(mbminmaxlen) ((mbminmaxlen) / DATA_MBMAX)
[20 Oct 2010 12:49] Marko Mäkelä
If you cast DATA_MBMINLEN to some type, you should also cast DATA_MBMAXLEN to the same type. Otherwise, warnings can be issued for assertions that compare these two.
[20 Oct 2010 12:59] 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/121315
[20 Oct 2010 12:59] 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/121316
[13 Nov 2010 16:12] Bugs System
Pushed into mysql-trunk 5.6.99-m5 (revid:alexander.nozdrin@oracle.com-20101113155825-czmva9kg4n31anmu) (version source revid:alexander.nozdrin@oracle.com-20101113152450-2zzcm50e7i4j35v7) (merge vers: 5.6.1-m4) (pib:21)
[13 Nov 2010 16:34] Bugs System
Pushed into mysql-next-mr (revid:alexander.nozdrin@oracle.com-20101113160336-atmtmfb3mzm4pz4i) (version source revid:vasil.dimov@oracle.com-20100629074804-359l9m9gniauxr94) (pib:21)
[16 Dec 2010 22:29] Bugs System
Pushed into mysql-5.5 5.5.9 (revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (version source revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (merge vers: 5.5.9) (pib:24)