[Commits] 81577de75b0: Fix many -Wconversion warnings.

marko.makela at mariadb.com marko.makela at mariadb.com
Mon Mar 6 19:28:53 EET 2017


revision-id: 81577de75b048c9e933dfc0322fc6c90fbf08c96 (mariadb-10.2.4-19-g81577de75b0)
parent(s): 5b07334b32f4add094981b8346fff468436e1e71
author: Marko Mäkelä
committer: Marko Mäkelä
timestamp: 2017-03-06 19:28:47 +0200
message:

Fix many -Wconversion warnings.

Define my_thread_id as an unsigned type, to avoid mismatch with
ulonglong.  Change some parameters to this type.

Use size_t in a few more places.

Declare many flag constants as unsigned to avoid sign mismatch
when shifting bits or applying the unary ~ operator.

When applying the unary ~ operator to enum constants, explictly
cast the result to an unsigned type, because enum constants can
be treated as signed.

In InnoDB, change the source code line number parameters from
ulint to unsigned type. Also, make some InnoDB functions return
a narrower type (unsigned or uint32_t instead of ulint;
bool instead of ibool).

---
 client/mysqldump.c                        |  16 +--
 dbug/dbug.c                               |  24 ++--
 extra/yassl/taocrypt/include/misc.hpp     |   9 +-
 extra/yassl/taocrypt/include/modes.hpp    |   5 +-
 include/my_base.h                         | 212 +++++++++++++++---------------
 include/my_bit.h                          |   4 +-
 include/my_global.h                       |   4 +-
 include/my_pthread.h                      |   4 +-
 include/my_sys.h                          | 142 ++++++++++----------
 include/my_time.h                         |  13 +-
 include/my_valgrind.h                     |   4 +-
 include/myisamchk.h                       |  11 +-
 include/mysql/psi/mysql_idle.h            |   3 +-
 include/mysql/psi/mysql_socket.h          |  15 +--
 include/mysql/psi/mysql_statement.h       |   3 +-
 include/mysql/psi/mysql_table.h           |   3 +-
 include/mysql_com.h                       |  90 ++++++-------
 include/thr_lock.h                        |   7 +-
 include/typelib.h                         |   5 +-
 include/violite.h                         |   8 +-
 mysys/ma_dyncol.c                         |  16 +--
 mysys/mf_keycache.c                       |  21 +--
 mysys_ssl/yassl.cc                        |   8 +-
 sql-common/my_time.c                      |  12 +-
 sql/create_options.cc                     |   4 +-
 sql/field.h                               |  52 ++++----
 sql/handler.h                             | 157 +++++++++++-----------
 sql/item.h                                |  12 +-
 sql/log.cc                                |  21 ++-
 sql/log.h                                 |  16 +--
 sql/log_event.h                           |   8 +-
 sql/log_slow.h                            |  31 +++--
 sql/mysqld.cc                             |   2 +-
 sql/mysqld.h                              |  24 ++--
 sql/session_tracker.h                     |   4 +-
 sql/sql_acl.h                             |  61 ++++-----
 sql/sql_audit.h                           |   3 +-
 sql/sql_class.h                           |   9 +-
 sql/sql_error.h                           |   3 +-
 sql/sql_lex.h                             |   6 +-
 sql/sql_plugin.h                          |  20 +--
 sql/sql_select.h                          |  16 +--
 sql/sql_string.h                          |  10 +-
 sql/sql_table.cc                          |   4 +-
 sql/sql_table.h                           |   4 +-
 sql/sql_trigger.h                         |   5 +-
 sql/structs.h                             |  37 +++---
 sql/sys_vars.cc                           |   2 +-
 sql/table.h                               |  56 ++++----
 storage/connect/blkfil.cpp                |   6 +-
 storage/innobase/btr/btr0btr.cc           |   8 +-
 storage/innobase/btr/btr0cur.cc           |  20 +--
 storage/innobase/btr/btr0defragment.cc    |   6 +-
 storage/innobase/btr/btr0pcur.cc          |   4 +-
 storage/innobase/btr/btr0scrub.cc         |  21 +--
 storage/innobase/btr/btr0sea.cc           |   7 +-
 storage/innobase/buf/buf0buf.cc           |  14 +-
 storage/innobase/data/data0data.cc        |   3 +-
 storage/innobase/data/data0type.cc        |  18 +--
 storage/innobase/dict/dict0dict.cc        |  14 +-
 storage/innobase/dict/dict0load.cc        |   6 +-
 storage/innobase/dict/dict0mem.cc         |   5 +-
 storage/innobase/fil/fil0crypt.cc         |   2 +-
 storage/innobase/fil/fil0fil.cc           |  41 +++---
 storage/innobase/fil/fil0pagecompress.cc  |   2 +-
 storage/innobase/fsp/fsp0fsp.cc           |   2 +-
 storage/innobase/gis/gis0sea.cc           |   6 +-
 storage/innobase/handler/ha_innodb.cc     |  25 +---
 storage/innobase/handler/handler0alter.cc |   2 +-
 storage/innobase/handler/i_s.cc           |  25 ++--
 storage/innobase/ibuf/ibuf0ibuf.cc        |   4 +-
 storage/innobase/include/btr0btr.h        |  64 ++++-----
 storage/innobase/include/btr0btr.ic       |   4 +-
 storage/innobase/include/btr0cur.h        |  13 +-
 storage/innobase/include/btr0pcur.h       |  11 +-
 storage/innobase/include/btr0pcur.ic      |   8 +-
 storage/innobase/include/buf0buf.h        |  22 ++--
 storage/innobase/include/buf0buf.ic       |  24 ++--
 storage/innobase/include/buf0flu.h        |   4 +-
 storage/innobase/include/data0data.ic     |   3 +-
 storage/innobase/include/data0type.h      |  50 +++----
 storage/innobase/include/data0type.ic     |   7 +-
 storage/innobase/include/dict0dict.h      |   8 +-
 storage/innobase/include/dict0dict.ic     |   2 +-
 storage/innobase/include/dict0mem.h       |  28 ++--
 storage/innobase/include/dict0mem.ic      |   3 +-
 storage/innobase/include/dict0stats.h     |  22 ++--
 storage/innobase/include/dict0stats.ic    |  29 ++--
 storage/innobase/include/dict0types.h     |   4 +-
 storage/innobase/include/fil0crypt.h      |   2 +-
 storage/innobase/include/fil0crypt.ic     |   4 +-
 storage/innobase/include/fil0fil.h        |   2 -
 storage/innobase/include/fsp0fsp.h        |   2 +-
 storage/innobase/include/fsp0types.h      |   2 +-
 storage/innobase/include/gis0rtree.h      |   7 +-
 storage/innobase/include/gis0rtree.ic     |   7 +-
 storage/innobase/include/ibuf0ibuf.h      |   4 +-
 storage/innobase/include/lock0lock.h      |  18 +--
 storage/innobase/include/lock0lock.ic     |   7 +-
 storage/innobase/include/mach0data.h      |  44 +++----
 storage/innobase/include/mach0data.ic     |  62 ++++-----
 storage/innobase/include/mem0mem.h        |   5 +-
 storage/innobase/include/mem0mem.ic       |   5 +-
 storage/innobase/include/mtr0mtr.h        |   8 +-
 storage/innobase/include/mtr0mtr.ic       |   7 +-
 storage/innobase/include/os0file.h        |  26 ++--
 storage/innobase/include/os0file.ic       |  25 ++--
 storage/innobase/include/page0page.ic     |   8 +-
 storage/innobase/include/page0size.h      |   4 +-
 storage/innobase/include/page0zip.h       |   7 +-
 storage/innobase/include/page0zip.ic      |  11 +-
 storage/innobase/include/rem0rec.h        |   3 +-
 storage/innobase/include/row0ins.h        |   3 +-
 storage/innobase/include/row0merge.h      |   6 +-
 storage/innobase/include/row0mysql.h      |   5 +-
 storage/innobase/include/row0upd.ic       |  18 +--
 storage/innobase/include/sync0arr.h       |   6 +-
 storage/innobase/include/sync0arr.ic      |   3 +-
 storage/innobase/include/sync0policy.h    |  25 ++--
 storage/innobase/include/sync0policy.ic   |   5 +-
 storage/innobase/include/sync0rw.h        |  32 ++---
 storage/innobase/include/sync0rw.ic       |  24 ++--
 storage/innobase/include/trx0rec.h        |   9 +-
 storage/innobase/include/trx0trx.h        |   6 +-
 storage/innobase/include/trx0types.h      |   3 +-
 storage/innobase/include/univ.i           |  16 +--
 storage/innobase/include/ut0dbg.h         |   7 +-
 storage/innobase/include/ut0mem.ic        |   9 +-
 storage/innobase/include/ut0mutex.h       |  17 ++-
 storage/innobase/lock/lock0lock.cc        |   6 +-
 storage/innobase/mem/mem0mem.cc           |   3 +-
 storage/innobase/mtr/mtr0log.cc           |   2 +-
 storage/innobase/mtr/mtr0mtr.cc           |  28 ++--
 storage/innobase/os/os0file.cc            |  12 +-
 storage/innobase/page/page0page.cc        |   4 +-
 storage/innobase/page/page0zip.cc         |  33 +++--
 storage/innobase/rem/rem0rec.cc           |   3 +-
 storage/innobase/row/row0ins.cc           |   6 +-
 storage/innobase/row/row0merge.cc         |   4 +-
 storage/innobase/row/row0mysql.cc         |   4 +-
 storage/innobase/row/row0trunc.cc         |   2 +-
 storage/innobase/srv/srv0start.cc         |   2 +-
 storage/innobase/sync/sync0arr.cc         |  51 ++++---
 storage/innobase/sync/sync0rw.cc          |  23 ++--
 storage/innobase/ut/ut0dbg.cc             |   5 +-
 storage/maria/ma_blockrec.h               |  22 ++--
 storage/maria/ma_loghandler.h             |   6 +-
 storage/maria/maria_chk.c                 |   4 +-
 storage/maria/maria_def.h                 |  88 ++++++-------
 storage/myisam/myisamdef.h                |  75 +++++------
 storage/perfschema/pfs_events_waits.h     |   9 +-
 storage/spider/spd_db_include.h           |  40 +++---
 152 files changed, 1314 insertions(+), 1335 deletions(-)

diff --git a/client/mysqldump.c b/client/mysqldump.c
index c5c94e07e96..a02dbdf3845 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -1,6 +1,6 @@
 /*
    Copyright (c) 2000, 2013, Oracle and/or its affiliates.
-   Copyright (c) 2010, 2016, MariaDB
+   Copyright (c) 2010, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -199,12 +199,12 @@ const char *compatible_mode_names[]=
 };
 #define MASK_ANSI_QUOTES \
 (\
- (1<<2)  | /* POSTGRESQL */\
- (1<<3)  | /* ORACLE     */\
- (1<<4)  | /* MSSQL      */\
- (1<<5)  | /* DB2        */\
- (1<<6)  | /* MAXDB      */\
- (1<<10)   /* ANSI       */\
+ (1U<<2)  | /* POSTGRESQL */\
+ (1U<<3)  | /* ORACLE     */\
+ (1U<<4)  | /* MSSQL      */\
+ (1U<<5)  | /* DB2        */\
+ (1U<<6)  | /* MAXDB      */\
+ (1U<<10)   /* ANSI       */\
 )
 TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
                                   "", compatible_mode_names, NULL};
@@ -5476,7 +5476,7 @@ static ulong find_set(TYPELIB *lib, const char *x, size_t length,
         *err_len= var_len;
       }
       else
-        found|= ((longlong) 1 << (find - 1));
+        found|= 1UL << (find - 1);
       if (pos == end)
         break;
       start= pos + 1;
diff --git a/dbug/dbug.c b/dbug/dbug.c
index 048e4803b1a..f51525897e2 100644
--- a/dbug/dbug.c
+++ b/dbug/dbug.c
@@ -115,18 +115,18 @@
  *      (until we add flags to _db_stack_frame_, increasing it by 4 bytes)
  */
 
-#define DEBUG_ON        (1 <<  1)  /* Debug enabled */
-#define FILE_ON         (1 <<  2)  /* File name print enabled */
-#define LINE_ON         (1 <<  3)  /* Line number print enabled */
-#define DEPTH_ON        (1 <<  4)  /* Function nest level print enabled */
-#define PROCESS_ON      (1 <<  5)  /* Process name print enabled */
-#define NUMBER_ON       (1 <<  6)  /* Number each line of output */
-#define PID_ON          (1 <<  8)  /* Identify each line with process id */
-#define TIMESTAMP_ON    (1 <<  9)  /* timestamp every line of output */
-#define FLUSH_ON_WRITE  (1 << 10)  /* Flush on every write */
-#define OPEN_APPEND     (1 << 11)  /* Open for append      */
-#define SANITY_CHECK_ON (1 << 12)  /* Check memory on every DBUG_ENTER/RETURN */
-#define TRACE_ON        ((uint)1 << 31)  /* Trace enabled. MUST be the highest bit!*/
+#define DEBUG_ON        (1U <<  1) /* Debug enabled */
+#define FILE_ON         (1U <<  2) /* File name print enabled */
+#define LINE_ON         (1U <<  3) /* Line number print enabled */
+#define DEPTH_ON        (1U <<  4) /* Function nest level print enabled */
+#define PROCESS_ON      (1U <<  5) /* Process name print enabled */
+#define NUMBER_ON       (1U <<  6) /* Number each line of output */
+#define PID_ON          (1U <<  8) /* Identify each line with process id */
+#define TIMESTAMP_ON    (1U <<  9) /* timestamp every line of output */
+#define FLUSH_ON_WRITE  (1U << 10) /* Flush on every write */
+#define OPEN_APPEND     (1U << 11) /* Open for append      */
+#define SANITY_CHECK_ON (1U << 12) /* Check memory on every DBUG_ENTER/RETURN */
+#define TRACE_ON        (1U << 31) /* Trace enabled. MUST be the highest bit!*/
 
 #define sf_sanity() (0)
 #define TRACING (cs->stack->flags & TRACE_ON)
diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp
index cb4d26e70c6..ef29269340b 100644
--- a/extra/yassl/taocrypt/include/misc.hpp
+++ b/extra/yassl/taocrypt/include/misc.hpp
@@ -1,5 +1,6 @@
 /*
    Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -599,8 +600,8 @@ inline word16 UnalignedGetWordNonTemplate(ByteOrder order, const byte* block,
                                           word16*)
 {
     return (order == BigEndianOrder)
-        ? block[1] | (block[0] << 8)
-        : block[0] | (block[1] << 8);
+        ? word16(block[1] | (word16(block[0]) << 8))
+        : word16(block[0] | (word16(block[1]) << 8));
 }
 
 inline word32 UnalignedGetWordNonTemplate(ByteOrder order, const byte* block,
@@ -625,7 +626,7 @@ inline void UnalignedPutWord(ByteOrder order, byte *block, byte value,
     block[0] = xorBlock ? (value ^ xorBlock[0]) : value;
 }
 
-#define GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y)))
+#define GETBYTE(x, y) byte((x)>>(8*(y)))
 
 inline void UnalignedPutWord(ByteOrder order, byte *block, word16 value,
                              const byte *xorBlock = 0)
@@ -827,7 +828,7 @@ word ShiftWordsLeftByBits(word* r, unsigned int n, unsigned int shiftBits)
 
 
 inline
-word ShiftWordsRightByBits(word* r, unsigned int n, unsigned int shiftBits)
+word ShiftWordsRightByBits(word* r, int n, unsigned int shiftBits)
 {
     word u, carry=0;
     if (shiftBits)
diff --git a/extra/yassl/taocrypt/include/modes.hpp b/extra/yassl/taocrypt/include/modes.hpp
index bfe8c6ec5d4..a14f3b0f956 100644
--- a/extra/yassl/taocrypt/include/modes.hpp
+++ b/extra/yassl/taocrypt/include/modes.hpp
@@ -1,5 +1,6 @@
 /*
    Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -57,7 +58,7 @@ class Mode_BASE : public virtual_base {
 public:
     enum { MaxBlockSz = 16 };
 
-    explicit Mode_BASE(int sz, CipherDir dir, Mode mode) 
+    explicit Mode_BASE(unsigned sz, CipherDir dir, Mode mode)
         : blockSz_(sz), reg_(reinterpret_cast<byte*>(r_)),
           tmp_(reinterpret_cast<byte*>(t_)), dir_(dir), mode_(mode)
     {}
@@ -67,7 +68,7 @@ public:
 
     void SetIV(const byte* iv) { memcpy(reg_, iv, blockSz_); }
 protected:
-    int   blockSz_;
+    unsigned blockSz_;
     byte* reg_;
     byte* tmp_;
 
diff --git a/include/my_base.h b/include/my_base.h
index 84b2e28d340..89f5e826fd5 100644
--- a/include/my_base.h
+++ b/include/my_base.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2000, 2012, Oracle and/or its affiliates.
-   Copyright (c) 1995, 2012 Monty Program Ab
+   Copyright (c) 1995, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -34,25 +34,25 @@
 
 /* The following is bits in the flag parameter to ha_open() */
 
-#define HA_OPEN_ABORT_IF_LOCKED		0	/* default */
-#define HA_OPEN_WAIT_IF_LOCKED		1
-#define HA_OPEN_IGNORE_IF_LOCKED	2
-#define HA_OPEN_TMP_TABLE		4	/* Table is a temp table */
-#define HA_OPEN_DELAY_KEY_WRITE		8	/* Don't update index  */
-#define HA_OPEN_ABORT_IF_CRASHED	16
-#define HA_OPEN_FOR_REPAIR		32	/* open even if crashed */
-#define HA_OPEN_FROM_SQL_LAYER          64
-#define HA_OPEN_MMAP                    128     /* open memory mapped */
-#define HA_OPEN_COPY			256     /* Open copy (for repair) */
+#define HA_OPEN_ABORT_IF_LOCKED		0U	/* default */
+#define HA_OPEN_WAIT_IF_LOCKED		1U
+#define HA_OPEN_IGNORE_IF_LOCKED	2U
+#define HA_OPEN_TMP_TABLE		4U	/* Table is a temp table */
+#define HA_OPEN_DELAY_KEY_WRITE		8U	/* Don't update index  */
+#define HA_OPEN_ABORT_IF_CRASHED	16U
+#define HA_OPEN_FOR_REPAIR		32U	/* open even if crashed */
+#define HA_OPEN_FROM_SQL_LAYER          64U
+#define HA_OPEN_MMAP                    128U    /* open memory mapped */
+#define HA_OPEN_COPY			256U    /* Open copy (for repair) */
 /* Internal temp table, used for temporary results */
-#define HA_OPEN_INTERNAL_TABLE          512
-#define HA_OPEN_NO_PSI_CALL             1024    /* Don't call/connect PSI */
-#define HA_OPEN_MERGE_TABLE		2048
+#define HA_OPEN_INTERNAL_TABLE          512U
+#define HA_OPEN_NO_PSI_CALL             1024U   /* Don't call/connect PSI */
+#define HA_OPEN_MERGE_TABLE		2048U
 /*
   Allow opening even if table is incompatible as this is for ALTER TABLE which
   will fix the table structure.
 */
-#define HA_OPEN_FOR_ALTER		4096
+#define HA_OPEN_FOR_ALTER		4096U
 
 /* The following is parameter to ha_rkey() how to use key */
 
@@ -248,15 +248,15 @@ enum ha_base_keytype {
   Note that these can only be up to 16 bits!
 */
 
-#define HA_NOSAME		 1	/* Set if not dupplicated records */
-#define HA_PACK_KEY		 2	/* Pack string key to previous key */
-#define HA_AUTO_KEY		 16
-#define HA_BINARY_PACK_KEY	 32	/* Packing of all keys to prev key */
-#define HA_FULLTEXT		128     /* For full-text search */
-#define HA_UNIQUE_CHECK		256	/* Check the key for uniqueness */
-#define HA_SPATIAL		1024    /* For spatial search */
-#define HA_NULL_ARE_EQUAL	2048	/* NULL in key are cmp as equal */
-#define HA_GENERATED_KEY	8192	/* Automaticly generated key */
+#define HA_NOSAME		 1U	/* Set if not dupplicated records */
+#define HA_PACK_KEY		 2U	/* Pack string key to previous key */
+#define HA_AUTO_KEY		 16U
+#define HA_BINARY_PACK_KEY	 32U	/* Packing of all keys to prev key */
+#define HA_FULLTEXT		128U    /* For full-text search */
+#define HA_UNIQUE_CHECK		256U	/* Check the key for uniqueness */
+#define HA_SPATIAL		1024U   /* For spatial search */
+#define HA_NULL_ARE_EQUAL	2048U	/* NULL in key are cmp as equal */
+#define HA_GENERATED_KEY	8192U	/* Automaticly generated key */
 
         /* The combination of the above can be used for key type comparison. */
 #define HA_KEYFLAG_MASK (HA_NOSAME | HA_PACK_KEY | HA_AUTO_KEY | \
@@ -303,25 +303,25 @@ enum ha_base_keytype {
 #define HA_CAN_MEMCMP           2048 /* internal, never stored in frm */
 
 	/* optionbits for database */
-#define HA_OPTION_PACK_RECORD		1
-#define HA_OPTION_PACK_KEYS		2
-#define HA_OPTION_COMPRESS_RECORD	4
-#define HA_OPTION_LONG_BLOB_PTR		8 /* new ISAM format */
-#define HA_OPTION_TMP_TABLE		16
-#define HA_OPTION_CHECKSUM		32
-#define HA_OPTION_DELAY_KEY_WRITE	64
-#define HA_OPTION_NO_PACK_KEYS		128  /* Reserved for MySQL */
+#define HA_OPTION_PACK_RECORD		1U
+#define HA_OPTION_PACK_KEYS		2U
+#define HA_OPTION_COMPRESS_RECORD	4U
+#define HA_OPTION_LONG_BLOB_PTR		8U /* new ISAM format */
+#define HA_OPTION_TMP_TABLE		16U
+#define HA_OPTION_CHECKSUM		32U
+#define HA_OPTION_DELAY_KEY_WRITE	64U
+#define HA_OPTION_NO_PACK_KEYS		128U  /* Reserved for MySQL */
 /* unused                               256 */
-#define HA_OPTION_RELIES_ON_SQL_LAYER   512
-#define HA_OPTION_NULL_FIELDS		1024
-#define HA_OPTION_PAGE_CHECKSUM		2048
+#define HA_OPTION_RELIES_ON_SQL_LAYER   512U
+#define HA_OPTION_NULL_FIELDS		1024U
+#define HA_OPTION_PAGE_CHECKSUM		2048U
 /*
    STATS_PERSISTENT=1 has been specified in the SQL command (either CREATE
    or ALTER TABLE). Table and index statistics that are collected by the
    storage engine and used by the optimizer for query optimization will be
    stored on disk and will not change after a server restart.
 */
-#define HA_OPTION_STATS_PERSISTENT	4096
+#define HA_OPTION_STATS_PERSISTENT	4096U
 /*
   STATS_PERSISTENT=0 has been specified in CREATE/ALTER TABLE. Statistics
   for the table will be wiped away on server shutdown and new ones recalculated
@@ -330,31 +330,31 @@ enum ha_base_keytype {
   explicitly set at table level and the corresponding table will use whatever
   is the global server default.
 */
-#define HA_OPTION_NO_STATS_PERSISTENT	8192
+#define HA_OPTION_NO_STATS_PERSISTENT	8192U
 
 /* .frm has extra create options in linked-list format */
-#define HA_OPTION_TEXT_CREATE_OPTIONS_legacy (1L << 14) /* 5.2 to 5.5, unused since 10.0 */
-#define HA_OPTION_TEMP_COMPRESS_RECORD  (1L << 15)      /* set by isamchk */
-#define HA_OPTION_READ_ONLY_DATA        (1L << 16)      /* Set by isamchk */
-#define HA_OPTION_NO_CHECKSUM           (1L << 17)
-#define HA_OPTION_NO_DELAY_KEY_WRITE    (1L << 18)
+#define HA_OPTION_TEXT_CREATE_OPTIONS_legacy (1U << 14) /* 5.2 to 5.5, unused since 10.0 */
+#define HA_OPTION_TEMP_COMPRESS_RECORD  (1U << 15)      /* set by isamchk */
+#define HA_OPTION_READ_ONLY_DATA        (1U << 16)      /* Set by isamchk */
+#define HA_OPTION_NO_CHECKSUM           (1U << 17)
+#define HA_OPTION_NO_DELAY_KEY_WRITE    (1U << 18)
 
 	/* Bits in flag to create() */
 
-#define HA_DONT_TOUCH_DATA	1	/* Don't empty datafile (isamchk) */
-#define HA_PACK_RECORD		2	/* Request packed record format */
-#define HA_CREATE_TMP_TABLE	4
-#define HA_CREATE_CHECKSUM	8
-#define HA_CREATE_KEEP_FILES	16      /* don't overwrite .MYD and MYI */
-#define HA_CREATE_PAGE_CHECKSUM	32
-#define HA_CREATE_DELAY_KEY_WRITE 64
-#define HA_CREATE_RELIES_ON_SQL_LAYER 128
-#define HA_CREATE_INTERNAL_TABLE 256
-#define HA_PRESERVE_INSERT_ORDER 512
+#define HA_DONT_TOUCH_DATA	1U	/* Don't empty datafile (isamchk) */
+#define HA_PACK_RECORD		2U	/* Request packed record format */
+#define HA_CREATE_TMP_TABLE	4U
+#define HA_CREATE_CHECKSUM	8U
+#define HA_CREATE_KEEP_FILES	16U     /* don't overwrite .MYD and MYI */
+#define HA_CREATE_PAGE_CHECKSUM	32U
+#define HA_CREATE_DELAY_KEY_WRITE 64U
+#define HA_CREATE_RELIES_ON_SQL_LAYER 128U
+#define HA_CREATE_INTERNAL_TABLE 256U
+#define HA_PRESERVE_INSERT_ORDER 512U
 
 /* Flags used by start_bulk_insert */
 
-#define HA_CREATE_UNIQUE_INDEX_BY_SORT   1
+#define HA_CREATE_UNIQUE_INDEX_BY_SORT   1U
 
 
 /*
@@ -366,44 +366,44 @@ enum ha_base_keytype {
 */
 
 /* this one is not used */
-#define HA_STATUS_POS            1
+#define HA_STATUS_POS            1U
 /*
   assuming the table keeps shared actual copy of the 'info' and
   local, possibly outdated copy, the following flag means that
   it should not try to get the actual data (locking the shared structure)
   slightly outdated version will suffice
 */
-#define HA_STATUS_NO_LOCK        2
+#define HA_STATUS_NO_LOCK        2U
 /* update the time of the last modification (in handler::update_time) */
-#define HA_STATUS_TIME           4
+#define HA_STATUS_TIME           4U
 /*
   update the 'constant' part of the info:
   handler::max_data_file_length, max_index_file_length, create_time
   sortkey, ref_length, block_size, data_file_name, index_file_name.
   handler::table->s->keys_in_use, keys_for_keyread, rec_per_key
 */
-#define HA_STATUS_CONST          8
+#define HA_STATUS_CONST          8U
 /*
   update the 'variable' part of the info:
   handler::records, deleted, data_file_length, index_file_length,
   check_time, mean_rec_length
 */
-#define HA_STATUS_VARIABLE      16
+#define HA_STATUS_VARIABLE      16U
 /*
   get the information about the key that caused last duplicate value error
   update handler::errkey and handler::dupp_ref
   see handler::get_dup_key()
 */
-#define HA_STATUS_ERRKEY        32
+#define HA_STATUS_ERRKEY        32U
 /*
   update handler::auto_increment_value
 */
-#define HA_STATUS_AUTO          64
+#define HA_STATUS_AUTO          64U
 /*
   Get also delete_length when HA_STATUS_VARIABLE is called. It's ok to set it also
   when only HA_STATUS_VARIABLE but it won't be used.
 */
-#define HA_STATUS_VARIABLE_EXTRA 128
+#define HA_STATUS_VARIABLE_EXTRA 128U
 
 /*
   Errorcodes given by handler functions
@@ -521,23 +521,23 @@ typedef ulong key_part_map;
 	/* Intern constants in databases */
 
 	/* bits in _search */
-#define SEARCH_FIND	1
-#define SEARCH_NO_FIND	2
-#define SEARCH_SAME	4
-#define SEARCH_BIGGER	8
-#define SEARCH_SMALLER	16
-#define SEARCH_SAVE_BUFF	32
-#define SEARCH_UPDATE	64
-#define SEARCH_PREFIX	128
-#define SEARCH_LAST	256
-#define MBR_CONTAIN     512
-#define MBR_INTERSECT   1024
-#define MBR_WITHIN      2048
-#define MBR_DISJOINT    4096
-#define MBR_EQUAL       8192
-#define MBR_DATA        16384
-#define SEARCH_NULL_ARE_EQUAL 32768	/* NULL in keys are equal */
-#define SEARCH_NULL_ARE_NOT_EQUAL 65536	/* NULL in keys are not equal */
+#define SEARCH_FIND	1U
+#define SEARCH_NO_FIND	2U
+#define SEARCH_SAME	4U
+#define SEARCH_BIGGER	8U
+#define SEARCH_SMALLER	16U
+#define SEARCH_SAVE_BUFF	32U
+#define SEARCH_UPDATE	64U
+#define SEARCH_PREFIX	128U
+#define SEARCH_LAST	256U
+#define MBR_CONTAIN     512U
+#define MBR_INTERSECT   1024U
+#define MBR_WITHIN      2048U
+#define MBR_DISJOINT    4096U
+#define MBR_EQUAL       8192U
+#define MBR_DATA        16384U
+#define SEARCH_NULL_ARE_EQUAL 32768U	/* NULL in keys are equal */
+#define SEARCH_NULL_ARE_NOT_EQUAL 65536U/* NULL in keys are not equal */
 /* Use this when inserting a key in position order */
 #define SEARCH_INSERT   (SEARCH_NULL_ARE_NOT_EQUAL*2)
 /* Only part of the key is specified while reading */
@@ -548,27 +548,27 @@ typedef ulong key_part_map;
 #define SEARCH_PAGE_KEY_HAS_TRANSID (SEARCH_USER_KEY_HAS_TRANSID*2)
 
 	/* bits in opt_flag */
-#define QUICK_USED	1
-#define READ_CACHE_USED	2
-#define READ_CHECK_USED 4
-#define KEY_READ_USED	8
-#define WRITE_CACHE_USED 16
-#define OPT_NO_ROWS	32
+#define QUICK_USED	1U
+#define READ_CACHE_USED	2U
+#define READ_CHECK_USED 4U
+#define KEY_READ_USED	8U
+#define WRITE_CACHE_USED 16U
+#define OPT_NO_ROWS	32U
 
 	/* bits in update */
-#define HA_STATE_CHANGED	1	/* Database has changed */
-#define HA_STATE_AKTIV		2	/* Has a current record */
-#define HA_STATE_WRITTEN	4	/* Record is written */
-#define HA_STATE_DELETED	8
-#define HA_STATE_NEXT_FOUND	16	/* Next found record (record before) */
-#define HA_STATE_PREV_FOUND	32	/* Prev found record (record after) */
-#define HA_STATE_NO_KEY		64	/* Last read didn't find record */
-#define HA_STATE_KEY_CHANGED	128
-#define HA_STATE_WRITE_AT_END	256	/* set in _ps_find_writepos */
-#define HA_STATE_BUFF_SAVED	512	/* If current keybuff is info->buff */
-#define HA_STATE_ROW_CHANGED	1024	/* To invalidate ROW cache */
-#define HA_STATE_EXTEND_BLOCK	2048
-#define HA_STATE_RNEXT_SAME	4096	/* rnext_same occupied lastkey2 */
+#define HA_STATE_CHANGED	1U	/* Database has changed */
+#define HA_STATE_AKTIV		2U	/* Has a current record */
+#define HA_STATE_WRITTEN	4U	/* Record is written */
+#define HA_STATE_DELETED	8U
+#define HA_STATE_NEXT_FOUND	16U	/* Next found record (record before) */
+#define HA_STATE_PREV_FOUND	32U	/* Prev found record (record after) */
+#define HA_STATE_NO_KEY		64U	/* Last read didn't find record */
+#define HA_STATE_KEY_CHANGED	128U
+#define HA_STATE_WRITE_AT_END	256U	/* set in _ps_find_writepos */
+#define HA_STATE_BUFF_SAVED	512U	/* If current keybuff is info->buff */
+#define HA_STATE_ROW_CHANGED	1024U	/* To invalidate ROW cache */
+#define HA_STATE_EXTEND_BLOCK	2048U
+#define HA_STATE_RNEXT_SAME	4096U	/* rnext_same occupied lastkey2 */
 
 /* myisampack expects no more than 32 field types. */
 enum en_fieldtype {
@@ -584,15 +584,15 @@ enum data_file_type {
 
 /* For key ranges */
 
-#define NO_MIN_RANGE	1
-#define NO_MAX_RANGE	2
-#define NEAR_MIN	4
-#define NEAR_MAX	8
-#define UNIQUE_RANGE	16
-#define EQ_RANGE	32
-#define NULL_RANGE	64
-#define GEOM_FLAG      128
-#define SKIP_RANGE     256
+#define NO_MIN_RANGE	1U
+#define NO_MAX_RANGE	2U
+#define NEAR_MIN	4U
+#define NEAR_MAX	8U
+#define UNIQUE_RANGE	16U
+#define EQ_RANGE	32U
+#define NULL_RANGE	64U
+#define GEOM_FLAG      128U
+#define SKIP_RANGE     256U
 
 typedef struct st_key_range
 {
diff --git a/include/my_bit.h b/include/my_bit.h
index a50403c312d..73a8f263f78 100644
--- a/include/my_bit.h
+++ b/include/my_bit.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2007, 2011, Oracle and/or its affiliates.
-   Copyright (c) 2009-2011, Monty Program Ab
+   Copyright (c) 2009, 2017, MariaDB Corporation. All Rights Reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -114,7 +114,7 @@ static inline uint32 my_clear_highest_bit(uint32 v)
 
 static inline uint32 my_reverse_bits(uint32 key)
 {
-  return
+  return (uint32)
     (_my_bits_reverse_table[ key      & 255] << 24) |
     (_my_bits_reverse_table[(key>> 8) & 255] << 16) |
     (_my_bits_reverse_table[(key>>16) & 255] <<  8) |
diff --git a/include/my_global.h b/include/my_global.h
index 4f40d3e0615..e4ca562772e 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -1,6 +1,6 @@
 /*
    Copyright (c) 2001, 2013, Oracle and/or its affiliates.
-   Copyright (c) 2010, 2013, Monty Program Ab.
+   Copyright (c) 2010, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -677,7 +677,7 @@ typedef SOCKET_SIZE_TYPE size_socket;
   smaller what the disk page size. This influences the speed of the
   isam btree library. eg to big to slow.
 */
-#define IO_SIZE			4096
+#define IO_SIZE			4096U
 /*
   How much overhead does malloc have. The code often allocates
   something like 1024-MALLOC_OVERHEAD bytes
diff --git a/include/my_pthread.h b/include/my_pthread.h
index bf61a024390..a38636af87d 100644
--- a/include/my_pthread.h
+++ b/include/my_pthread.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2000, 2014, Oracle and/or its affiliates.
-   Copyright (c) 2009, 2014, MariaDB
+   Copyright (c) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -651,7 +651,7 @@ extern pthread_mutexattr_t my_errorcheck_mutexattr;
 #define ESRCH 1
 #endif
 
-typedef int64 my_thread_id;
+typedef uint64 my_thread_id;
 
 extern void my_threadattr_global_init(void);
 extern my_bool my_thread_global_init(void);
diff --git a/include/my_sys.h b/include/my_sys.h
index 2e24bfd02d3..6834bbd8dc2 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
-   Copyright (c) 2010, 2016, Monty Program Ab.
+   Copyright (c) 2010, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -60,75 +60,75 @@ typedef struct my_aio_result {
 #define MY_FILE_ERROR	((size_t) -1)
 
 	/* General bitmaps for my_func's */
-#define MY_FFNF		1	/* Fatal if file not found */
-#define MY_FNABP	2	/* Fatal if not all bytes read/writen */
-#define MY_NABP		4	/* Error if not all bytes read/writen */
-#define MY_FAE		8	/* Fatal if any error */
-#define MY_WME		16	/* Write message on error */
-#define MY_WAIT_IF_FULL 32	/* Wait and try again if disk full error */
-#define MY_IGNORE_BADFD 32      /* my_sync: ignore 'bad descriptor' errors */
-#define MY_ENCRYPT      64      /* Encrypt IO_CACHE temporary files */
-#define MY_FULL_IO     512      /* For my_read - loop intil I/O is complete */
-#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
-#define MY_LINK_WARNING 32	/* my_redel() gives warning if links */
-#define MY_COPYTIME	64	/* my_redel() copys time */
-#define MY_DELETE_OLD	256	/* my_create_with_symlink() */
-#define MY_RESOLVE_LINK 128	/* my_realpath(); Only resolve links */
-#define MY_HOLD_ORIGINAL_MODES 128  /* my_copy() holds to file modes */
-#define MY_REDEL_MAKE_BACKUP 256
-#define MY_SEEK_NOT_DONE 32	/* my_lock may have to do a seek */
-#define MY_SHORT_WAIT	64	/* my_lock() don't wait if can't lock */
-#define MY_FORCE_LOCK   128     /* use my_lock() even if disable_locking */
-#define MY_NO_WAIT      256	/* my_lock() don't wait at all */
+#define MY_FFNF		1U	/* Fatal if file not found */
+#define MY_FNABP	2U	/* Fatal if not all bytes read/writen */
+#define MY_NABP		4U	/* Error if not all bytes read/writen */
+#define MY_FAE		8U	/* Fatal if any error */
+#define MY_WME		16U	/* Write message on error */
+#define MY_WAIT_IF_FULL 32U	/* Wait and try again if disk full error */
+#define MY_IGNORE_BADFD 32U     /* my_sync: ignore 'bad descriptor' errors */
+#define MY_ENCRYPT      64U     /* Encrypt IO_CACHE temporary files */
+#define MY_FULL_IO     512U     /* For my_read - loop intil I/O is complete */
+#define MY_DONT_CHECK_FILESIZE 128U /* Option to init_io_cache() */
+#define MY_LINK_WARNING 32U	/* my_redel() gives warning if links */
+#define MY_COPYTIME	64U	/* my_redel() copys time */
+#define MY_DELETE_OLD	256U	/* my_create_with_symlink() */
+#define MY_RESOLVE_LINK 128U	/* my_realpath(); Only resolve links */
+#define MY_HOLD_ORIGINAL_MODES 128U  /* my_copy() holds to file modes */
+#define MY_REDEL_MAKE_BACKUP 256U
+#define MY_SEEK_NOT_DONE 32U	/* my_lock may have to do a seek */
+#define MY_SHORT_WAIT	64U	/* my_lock() don't wait if can't lock */
+#define MY_FORCE_LOCK   128U    /* use my_lock() even if disable_locking */
+#define MY_NO_WAIT      256U	/* my_lock() don't wait at all */
 /*
   init_dynamic_array() has init buffer; Internal flag, not to be used by
   caller.
 */
-#define MY_INIT_BUFFER_USED 256
-#define MY_ZEROFILL	32	/* my_malloc(), fill array with zero */
-#define MY_ALLOW_ZERO_PTR 64	/* my_realloc() ; zero ptr -> malloc */
-#define MY_FREE_ON_ERROR 128	/* my_realloc() ; Free old ptr on error */
-#define MY_HOLD_ON_ERROR 256	/* my_realloc() ; Return old ptr on error */
-#define MY_DONT_OVERWRITE_FILE 2048 /* my_copy: Don't overwrite file */
-#define MY_THREADSAFE 2048      /* my_seek(): lock fd mutex */
-#define MY_SYNC       4096      /* my_copy(): sync dst file */
-#define MY_SYNC_DIR   32768     /* my_create/delete/rename: sync directory */
-#define MY_SYNC_FILESIZE 65536  /* my_sync(): safe sync when file is extended */
-#define MY_THREAD_SPECIFIC 0x10000  /* my_malloc(): thread specific */
-#define MY_THREAD_MOVE     0x20000  /* realloc(); Memory can move */
-/* Tree that should delete things automaticly */ 
-#define MY_TREE_WITH_DELETE 0x40000
-
-#define MY_CHECK_ERROR	1	/* Params to my_end; Check open-close */
-#define MY_GIVE_INFO	2	/* Give time info about process*/
-#define MY_DONT_FREE_DBUG 4     /* Do not call DBUG_END() in my_end() */
-
-#define ME_HIGHBYTE	8	/* Shift for colours */
-#define ME_NOCUR	1	/* Don't use curses message */
-#define ME_OLDWIN	2	/* Use old window */
-#define ME_BELL		4	/* Ring bell then printing message */
-#define ME_HOLDTANG	8	/* Don't delete last keys */
-#define ME_WAITTOT	16	/* Wait for errtime secs of for a action */
-#define ME_WAITTANG	32	/* Wait for a user action  */
-#define ME_NOREFRESH	64	/* Write the error message to error log */
-#define ME_NOINPUT	128	/* Dont use the input libary */
-#define ME_COLOUR1	((1 << ME_HIGHBYTE))	/* Possibly error-colours */
-#define ME_COLOUR2	((2 << ME_HIGHBYTE))
-#define ME_COLOUR3	((3 << ME_HIGHBYTE))
-#define ME_JUST_INFO    1024    /**< not error but just info */
-#define ME_JUST_WARNING 2048    /**< not error but just warning */
-#define ME_FATALERROR   4096    /* Fatal statement error */
+#define MY_INIT_BUFFER_USED 256U
+#define MY_ZEROFILL	32U	/* my_malloc(), fill array with zero */
+#define MY_ALLOW_ZERO_PTR 64U	/* my_realloc() ; zero ptr -> malloc */
+#define MY_FREE_ON_ERROR 128U	/* my_realloc() ; Free old ptr on error */
+#define MY_HOLD_ON_ERROR 256U	/* my_realloc() ; Return old ptr on error */
+#define MY_DONT_OVERWRITE_FILE 2048U /* my_copy: Don't overwrite file */
+#define MY_THREADSAFE 2048U     /* my_seek(): lock fd mutex */
+#define MY_SYNC       4096U     /* my_copy(): sync dst file */
+#define MY_SYNC_DIR   32768U    /* my_create/delete/rename: sync directory */
+#define MY_SYNC_FILESIZE 65536U /* my_sync(): safe sync when file is extended */
+#define MY_THREAD_SPECIFIC 0x10000U /* my_malloc(): thread specific */
+#define MY_THREAD_MOVE     0x20000U /* realloc(); Memory can move */
+/* Tree that should delete things automaticly */
+#define MY_TREE_WITH_DELETE 0x40000U
+
+#define MY_CHECK_ERROR	1U	/* Params to my_end; Check open-close */
+#define MY_GIVE_INFO	2U	/* Give time info about process*/
+#define MY_DONT_FREE_DBUG 4U    /* Do not call DBUG_END() in my_end() */
+
+#define ME_HIGHBYTE	8U	/* Shift for colours */
+#define ME_NOCUR	1U	/* Don't use curses message */
+#define ME_OLDWIN	2U	/* Use old window */
+#define ME_BELL		4U	/* Ring bell then printing message */
+#define ME_HOLDTANG	8U	/* Don't delete last keys */
+#define ME_WAITTOT	16U	/* Wait for errtime secs of for a action */
+#define ME_WAITTANG	32U	/* Wait for a user action  */
+#define ME_NOREFRESH	64U	/* Write the error message to error log */
+#define ME_NOINPUT	128U	/* Dont use the input libary */
+#define ME_COLOUR1	((1U << ME_HIGHBYTE))	/* Possibly error-colours */
+#define ME_COLOUR2	((2U << ME_HIGHBYTE))
+#define ME_COLOUR3	((3U << ME_HIGHBYTE))
+#define ME_JUST_INFO    1024U   /**< not error but just info */
+#define ME_JUST_WARNING 2048U   /**< not error but just warning */
+#define ME_FATALERROR   4096U   /* Fatal statement error */
 
 	/* Bits in last argument to fn_format */
-#define MY_REPLACE_DIR		1	/* replace dir in name with 'dir' */
-#define MY_REPLACE_EXT		2	/* replace extension with 'ext' */
-#define MY_UNPACK_FILENAME	4	/* Unpack name (~ -> home) */
-#define MY_PACK_FILENAME	8	/* Pack name (home -> ~) */
-#define MY_RESOLVE_SYMLINKS	16	/* Resolve all symbolic links */
-#define MY_RETURN_REAL_PATH	32	/* return full path for file */
-#define MY_SAFE_PATH		64	/* Return NULL if too long path */
-#define MY_RELATIVE_PATH	128	/* name is relative to 'dir' */
-#define MY_APPEND_EXT           256     /* add 'ext' as additional extension*/
+#define MY_REPLACE_DIR		1U	/* replace dir in name with 'dir' */
+#define MY_REPLACE_EXT		2U	/* replace extension with 'ext' */
+#define MY_UNPACK_FILENAME	4U	/* Unpack name (~ -> home) */
+#define MY_PACK_FILENAME	8U	/* Pack name (home -> ~) */
+#define MY_RESOLVE_SYMLINKS	16U	/* Resolve all symbolic links */
+#define MY_RETURN_REAL_PATH	32U	/* return full path for file */
+#define MY_SAFE_PATH		64U	/* Return NULL if too long path */
+#define MY_RELATIVE_PATH	128U	/* name is relative to 'dir' */
+#define MY_APPEND_EXT           256U    /* add 'ext' as additional extension*/
 
 
 	/* My seek flags */
@@ -143,19 +143,19 @@ typedef struct my_aio_result {
 #define DFLT_INIT_HITS  3
 
 	/* root_alloc flags */
-#define MY_KEEP_PREALLOC	1
-#define MY_MARK_BLOCKS_FREE     2  /* move used to free list and reuse them */
+#define MY_KEEP_PREALLOC	1U
+#define MY_MARK_BLOCKS_FREE     2U /* move used to free list and reuse them */
 
 	/* Internal error numbers (for assembler functions) */
 #define MY_ERRNO_EDOM		33
 #define MY_ERRNO_ERANGE		34
 
 	/* Bits for get_date timeflag */
-#define GETDATE_DATE_TIME	1
-#define GETDATE_SHORT_DATE	2
-#define GETDATE_HHMMSSTIME	4
-#define GETDATE_GMT		8
-#define GETDATE_FIXEDLENGTH	16
+#define GETDATE_DATE_TIME	1U
+#define GETDATE_SHORT_DATE	2U
+#define GETDATE_HHMMSSTIME	4U
+#define GETDATE_GMT		8U
+#define GETDATE_FIXEDLENGTH	16U
 
 /* Extra length needed for filename if one calls my_create_backup_name */
 #define MY_BACKUP_NAME_EXTRA_LENGTH 17
diff --git a/include/my_time.h b/include/my_time.h
index 8dc1f09ba0f..90d19c8861a 100644
--- a/include/my_time.h
+++ b/include/my_time.h
@@ -1,5 +1,6 @@
 /*
    Copyright (c) 2004, 2011, Oracle and/or its affiliates.
+   Copyright (c) 2017, Monty Program Ab.
 
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
@@ -61,16 +62,16 @@ extern uchar days_in_month[];
   TIME_FUZZY_DATES is used for the result will only be used for comparison
   purposes. Conversion is as relaxed as possible.
 */
-#define TIME_FUZZY_DATES        1
-#define TIME_DATETIME_ONLY	2
-#define TIME_TIME_ONLY	        4
+#define TIME_FUZZY_DATES        1U
+#define TIME_DATETIME_ONLY	2U
+#define TIME_TIME_ONLY	        4U
 #define TIME_NO_ZERO_IN_DATE    (1UL << 23) /* == MODE_NO_ZERO_IN_DATE */
 #define TIME_NO_ZERO_DATE	(1UL << 24) /* == MODE_NO_ZERO_DATE    */
 #define TIME_INVALID_DATES	(1UL << 25) /* == MODE_INVALID_DATES   */
 
-#define MYSQL_TIME_WARN_TRUNCATED    1
-#define MYSQL_TIME_WARN_OUT_OF_RANGE 2
-#define MYSQL_TIME_NOTE_TRUNCATED    16
+#define MYSQL_TIME_WARN_TRUNCATED    1U
+#define MYSQL_TIME_WARN_OUT_OF_RANGE 2U
+#define MYSQL_TIME_NOTE_TRUNCATED    16U
 
 #define MYSQL_TIME_WARN_WARNINGS (MYSQL_TIME_WARN_TRUNCATED|MYSQL_TIME_WARN_OUT_OF_RANGE)
 #define MYSQL_TIME_WARN_NOTES    (MYSQL_TIME_NOTE_TRUNCATED)
diff --git a/include/my_valgrind.h b/include/my_valgrind.h
index 9ceb49c1094..3519d7bb757 100644
--- a/include/my_valgrind.h
+++ b/include/my_valgrind.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2010 Monty Program Ab
+/* Copyright (C) 2010, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -38,7 +38,7 @@
 #define TRASH_FILL(A,B,C) do{ const size_t trash_tmp __attribute__((unused)) = (B) ; MEM_CHECK_ADDRESSABLE(A,trash_tmp);MEM_UNDEFINED(A,trash_tmp);} while (0)
 #endif
 #define TRASH_ALLOC(A,B) TRASH_FILL(A,B,0xA5)
-#define TRASH_FREE(A,B) TRASH_FILL(A,B,0x8F)
+#define TRASH_FREE(A,B) TRASH_FILL(A,(size_t) (B),0x8F)
 #define TRASH(A,B) TRASH_FREE(A,B)
 
 # define DBUG_ASSERT_DEFINED(x) \
diff --git a/include/myisamchk.h b/include/myisamchk.h
index 643241d84e5..40aa0b19d49 100644
--- a/include/myisamchk.h
+++ b/include/myisamchk.h
@@ -1,4 +1,5 @@
 /* Copyright (C) 2006 MySQL AB
+   Copyright (c) 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -24,13 +25,13 @@
   to xxxcheck.c follows:
 */
 
-#define TT_USEFRM               1
-#define TT_FOR_UPGRADE          2
-#define TT_FROM_MYSQL           4
+#define TT_USEFRM               1U
+#define TT_FOR_UPGRADE          2U
+#define TT_FROM_MYSQL           4U
 
 /* Bits set in out_flag */
-#define O_NEW_DATA	2
-#define O_DATA_LOST	4
+#define O_NEW_DATA	2U
+#define O_DATA_LOST	4U
 
 typedef struct st_sort_key_blocks		/* Used when sorting */
 {
diff --git a/include/mysql/psi/mysql_idle.h b/include/mysql/psi/mysql_idle.h
index 5c72b715b7a..6dd6ea26be9 100644
--- a/include/mysql/psi/mysql_idle.h
+++ b/include/mysql/psi/mysql_idle.h
@@ -1,4 +1,5 @@
 /* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.   
+   Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -67,7 +68,7 @@
 */
 static inline struct PSI_idle_locker *
 inline_mysql_start_idle_wait(PSI_idle_locker_state *state,
-                             const char *src_file, int src_line)
+                             const char *src_file, uint src_line)
 {
   struct PSI_idle_locker *locker;
   locker= PSI_IDLE_CALL(start_idle_wait)(state, src_file, src_line);
diff --git a/include/mysql/psi/mysql_socket.h b/include/mysql/psi/mysql_socket.h
index 619f600a776..e77f0159777 100644
--- a/include/mysql/psi/mysql_socket.h
+++ b/include/mysql/psi/mysql_socket.h
@@ -1,4 +1,5 @@
 /* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as
@@ -241,7 +242,7 @@ inline_mysql_start_socket_wait(PSI_socket_locker_state *state,
                                MYSQL_SOCKET mysql_socket,
                                enum PSI_socket_operation op,
                                size_t byte_count,
-                               const char *src_file, int src_line)
+                               const char *src_file, uint src_line)
 {
   struct PSI_socket_locker *locker;
   if (mysql_socket.m_psi != NULL)
@@ -744,8 +745,7 @@ inline_mysql_socket_send
     /* Instrumentation end */
     if (locker != NULL)
     {
-      size_t bytes_written;
-      bytes_written= (result > -1) ? result : 0;
+      size_t bytes_written= (result > 0) ? (size_t) result : 0;
       PSI_SOCKET_CALL(end_socket_wait)(locker, bytes_written);
     }
 
@@ -786,8 +786,7 @@ inline_mysql_socket_recv
     /* Instrumentation end */
     if (locker != NULL)
     {
-      size_t bytes_read;
-      bytes_read= (result > -1) ? result : 0;
+      size_t bytes_read= (result > 0) ? (size_t) result : 0;
       PSI_SOCKET_CALL(end_socket_wait)(locker, bytes_read);
     }
 
@@ -828,8 +827,7 @@ inline_mysql_socket_sendto
     /* Instrumentation end */
     if (locker != NULL)
     {
-      size_t bytes_written;
-      bytes_written = (result > -1) ? result : 0;
+      size_t bytes_written = (result > 0) ? (size_t) result : 0;
       PSI_SOCKET_CALL(end_socket_wait)(locker, bytes_written);
     }
 
@@ -871,8 +869,7 @@ inline_mysql_socket_recvfrom
     /* Instrumentation end */
     if (locker != NULL)
     {
-      size_t bytes_read;
-      bytes_read = (result > -1) ? result : 0;
+      size_t bytes_read= (result > 0) ? (size_t) result : 0;
       PSI_SOCKET_CALL(end_socket_wait)(locker, bytes_read);
     }
 
diff --git a/include/mysql/psi/mysql_statement.h b/include/mysql/psi/mysql_statement.h
index 3d5943fa55a..78b6d926996 100644
--- a/include/mysql/psi/mysql_statement.h
+++ b/include/mysql/psi/mysql_statement.h
@@ -1,4 +1,5 @@
 /* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.   
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -146,7 +147,7 @@ inline_mysql_start_statement(PSI_statement_locker_state *state,
                              PSI_statement_key key,
                              const char *db, uint db_len,
                              const CHARSET_INFO *charset,
-                             const char *src_file, int src_line)
+                             const char *src_file, uint src_line)
 {
   PSI_statement_locker *locker;
   locker= PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset);
diff --git a/include/mysql/psi/mysql_table.h b/include/mysql/psi/mysql_table.h
index 74217a32b13..5292b6a7386 100644
--- a/include/mysql/psi/mysql_table.h
+++ b/include/mysql/psi/mysql_table.h
@@ -1,4 +1,5 @@
 /* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -183,7 +184,7 @@ static inline struct PSI_table_locker *
 inline_mysql_start_table_lock_wait(PSI_table_locker_state *state,
                                    struct PSI_table *psi,
                                    enum PSI_table_lock_operation op,
-                                   ulong flags, const char *src_file, int src_line)
+                                   ulong flags, const char *src_file, uint src_line)
 {
   if (psi != NULL)
   {
diff --git a/include/mysql_com.h b/include/mysql_com.h
index ba389933b15..2cb4656ceef 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates.
-   Copyright (c) 2010, 2013, Monty Program Ab
+   Copyright (c) 2010, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -25,8 +25,8 @@
 
 #define HOSTNAME_LENGTH 60
 #define SYSTEM_CHARSET_MBMAXLEN 3
-#define NAME_CHAR_LEN	64              /* Field/table name length */
-#define USERNAME_CHAR_LENGTH 128
+#define NAME_CHAR_LEN	64U             /* Field/table name length */
+#define USERNAME_CHAR_LENGTH 128U
 #define NAME_LEN                (NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN)
 #define USERNAME_LENGTH         (USERNAME_CHAR_LENGTH*SYSTEM_CHARSET_MBMAXLEN)
 #define DEFINER_CHAR_LENGTH     (USERNAME_CHAR_LENGTH + HOSTNAME_LENGTH + 1)
@@ -149,40 +149,40 @@ enum enum_indicator_type
 #define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323*2)
 
 
-#define NOT_NULL_FLAG	1		/* Field can't be NULL */
-#define PRI_KEY_FLAG	2		/* Field is part of a primary key */
-#define UNIQUE_KEY_FLAG 4		/* Field is part of a unique key */
-#define MULTIPLE_KEY_FLAG 8		/* Field is part of a key */
-#define BLOB_FLAG	16		/* Field is a blob */
-#define UNSIGNED_FLAG	32		/* Field is unsigned */
-#define ZEROFILL_FLAG	64		/* Field is zerofill */
-#define BINARY_FLAG	128		/* Field is binary   */
+#define NOT_NULL_FLAG	1U		/* Field can't be NULL */
+#define PRI_KEY_FLAG	2U		/* Field is part of a primary key */
+#define UNIQUE_KEY_FLAG 4U		/* Field is part of a unique key */
+#define MULTIPLE_KEY_FLAG 8U		/* Field is part of a key */
+#define BLOB_FLAG	16U		/* Field is a blob */
+#define UNSIGNED_FLAG	32U		/* Field is unsigned */
+#define ZEROFILL_FLAG	64U		/* Field is zerofill */
+#define BINARY_FLAG	128U		/* Field is binary   */
 
 /* The following are only sent to new clients */
-#define ENUM_FLAG	256		/* field is an enum */
-#define AUTO_INCREMENT_FLAG 512		/* field is a autoincrement field */
-#define TIMESTAMP_FLAG	1024		/* Field is a timestamp */
-#define SET_FLAG	2048		/* field is a set */
-#define NO_DEFAULT_VALUE_FLAG 4096	/* Field doesn't have default value */
-#define ON_UPDATE_NOW_FLAG 8192         /* Field is set to NOW on UPDATE */
-#define NUM_FLAG	32768		/* Field is num (for clients) */
-#define PART_KEY_FLAG	16384		/* Intern; Part of some key */
-#define GROUP_FLAG	32768		/* Intern: Group field */
-#define BINCMP_FLAG	131072		/* Intern: Used by sql_yacc */
-#define GET_FIXED_FIELDS_FLAG (1 << 18) /* Used to get fields in item tree */
-#define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */
+#define ENUM_FLAG	256U		/* field is an enum */
+#define AUTO_INCREMENT_FLAG 512U	/* field is a autoincrement field */
+#define TIMESTAMP_FLAG	1024U		/* Field is a timestamp */
+#define SET_FLAG	2048U		/* field is a set */
+#define NO_DEFAULT_VALUE_FLAG 4096U	/* Field doesn't have default value */
+#define ON_UPDATE_NOW_FLAG 8192U	/* Field is set to NOW on UPDATE */
+#define NUM_FLAG	32768U		/* Field is num (for clients) */
+#define PART_KEY_FLAG	16384U		/* Intern; Part of some key */
+#define GROUP_FLAG	32768U		/* Intern: Group field */
+#define BINCMP_FLAG	131072U		/* Intern: Used by sql_yacc */
+#define GET_FIXED_FIELDS_FLAG (1U << 18) /* Used to get fields in item tree */
+#define FIELD_IN_PART_FUNC_FLAG (1U << 19)/* Field part of partition func */
 
 /**
   Intern: Field in TABLE object for new version of altered table,
           which participates in a newly added index.
 */
-#define FIELD_IN_ADD_INDEX (1 << 20)
-#define FIELD_IS_RENAMED (1<< 21)       /* Intern: Field is being renamed */
+#define FIELD_IN_ADD_INDEX (1U << 20)
+#define FIELD_IS_RENAMED (1U << 21)     /* Intern: Field is being renamed */
 #define FIELD_FLAGS_STORAGE_MEDIA 22    /* Field storage media, bit 22-23 */
-#define FIELD_FLAGS_STORAGE_MEDIA_MASK (3 << FIELD_FLAGS_STORAGE_MEDIA)
+#define FIELD_FLAGS_STORAGE_MEDIA_MASK (3U << FIELD_FLAGS_STORAGE_MEDIA)
 #define FIELD_FLAGS_COLUMN_FORMAT 24    /* Field column format, bit 24-25 */
-#define FIELD_FLAGS_COLUMN_FORMAT_MASK (3 << FIELD_FLAGS_COLUMN_FORMAT)
-#define FIELD_IS_DROPPED (1<< 26)       /* Intern: Field is being dropped */
+#define FIELD_FLAGS_COLUMN_FORMAT_MASK (3U << FIELD_FLAGS_COLUMN_FORMAT)
+#define FIELD_IS_DROPPED (1U << 26)     /* Intern: Field is being dropped */
 
 #define REFRESH_GRANT           (1ULL << 0)  /* Refresh grant tables */
 #define REFRESH_LOG             (1ULL << 1)  /* Start on new log file */
@@ -335,36 +335,36 @@ enum enum_indicator_type
   implicitly, by the first transactional
   statement, when autocommit=off.
 */
-#define SERVER_STATUS_IN_TRANS     1
-#define SERVER_STATUS_AUTOCOMMIT   2	/* Server in auto_commit mode */
-#define SERVER_MORE_RESULTS_EXISTS 8    /* Multi query - next query exists */
-#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
-#define SERVER_QUERY_NO_INDEX_USED      32
+#define SERVER_STATUS_IN_TRANS     1U
+#define SERVER_STATUS_AUTOCOMMIT   2U	/* Server in auto_commit mode */
+#define SERVER_MORE_RESULTS_EXISTS 8U   /* Multi query - next query exists */
+#define SERVER_QUERY_NO_GOOD_INDEX_USED 16U
+#define SERVER_QUERY_NO_INDEX_USED      32U
 /**
   The server was able to fulfill the clients request and opened a
   read-only non-scrollable cursor for a query. This flag comes
   in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
 */
-#define SERVER_STATUS_CURSOR_EXISTS 64
+#define SERVER_STATUS_CURSOR_EXISTS 64U
 /**
   This flag is sent when a read-only cursor is exhausted, in reply to
   COM_STMT_FETCH command.
 */
-#define SERVER_STATUS_LAST_ROW_SENT 128
-#define SERVER_STATUS_DB_DROPPED        256 /* A database was dropped */
-#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
+#define SERVER_STATUS_LAST_ROW_SENT 128U
+#define SERVER_STATUS_DB_DROPPED        256U /* A database was dropped */
+#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512U
 /**
   Sent to the client if after a prepared statement reprepare
   we discovered that the new statement returns a different 
   number of result set columns.
 */
-#define SERVER_STATUS_METADATA_CHANGED 1024
-#define SERVER_QUERY_WAS_SLOW          2048
+#define SERVER_STATUS_METADATA_CHANGED 1024U
+#define SERVER_QUERY_WAS_SLOW          2048U
 
 /**
   To mark ResultSet containing output parameter values.
 */
-#define SERVER_PS_OUT_PARAMS            4096
+#define SERVER_PS_OUT_PARAMS            4096U
 
 /**
   Set at the same time as SERVER_STATUS_IN_TRANS if the started
@@ -373,7 +373,7 @@ enum enum_indicator_type
   to clients in OK and EOF packets, the flag indicates the
   transaction status at the end of command execution.
 */
-#define SERVER_STATUS_IN_TRANS_READONLY 8192
+#define SERVER_STATUS_IN_TRANS_READONLY 8192U
 
 /**
   This status flag, when on, implies that one of the state information has
@@ -455,7 +455,7 @@ typedef struct st_net {
 } NET;
 
 
-#define packet_error (~(unsigned long) 0)
+#define packet_error ~0UL
 
 enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
 			MYSQL_TYPE_SHORT,  MYSQL_TYPE_LONG,
@@ -706,9 +706,9 @@ void my_thread_end(void);
 }
 #endif
 
-#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
-#define MYSQL_STMT_HEADER       4
-#define MYSQL_LONG_DATA_HEADER  6
+#define NULL_LENGTH ~0UL /* For net_store_length */
+#define MYSQL_STMT_HEADER       4U
+#define MYSQL_LONG_DATA_HEADER  6U
 
 /*
   If a float or double field have more than this number of decimals,
diff --git a/include/thr_lock.h b/include/thr_lock.h
index fb69d8a693e..4d3fa1f880c 100644
--- a/include/thr_lock.h
+++ b/include/thr_lock.h
@@ -1,4 +1,5 @@
 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -76,10 +77,10 @@ enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
 
 
 /* Priority for locks */
-#define THR_LOCK_LATE_PRIV  1	/* For locks to be merged with org lock */
-#define THR_LOCK_MERGE_PRIV 2	/* For merge tables */
+#define THR_LOCK_LATE_PRIV  1U	/* For locks to be merged with org lock */
+#define THR_LOCK_MERGE_PRIV 2U	/* For merge tables */
 
-#define THR_UNLOCK_UPDATE_STATUS 1
+#define THR_UNLOCK_UPDATE_STATUS 1U
 
 extern ulong max_write_lock_count;
 extern my_bool thr_lock_inited;
diff --git a/include/typelib.h b/include/typelib.h
index 4504bea4ff7..998f741dd87 100644
--- a/include/typelib.h
+++ b/include/typelib.h
@@ -1,4 +1,5 @@
 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -33,13 +34,13 @@ extern int find_type_or_exit(const char *x, TYPELIB *typelib,
                              const char *option);
 #define FIND_TYPE_BASIC           0
 /** makes @c find_type() require the whole name, no prefix */
-#define FIND_TYPE_NO_PREFIX      (1 << 0)
+#define FIND_TYPE_NO_PREFIX      (1U << 0)
 /** always implicitely on, so unused, but old code may pass it */
 #define FIND_TYPE_NO_OVERWRITE   0
 /** makes @c find_type() accept a number. Not used either */
 #define FIND_TYPE_ALLOW_NUMBER   0
 /** makes @c find_type() treat ',' and '=' as terminators */
-#define FIND_TYPE_COMMA_TERM     (1 << 3)
+#define FIND_TYPE_COMMA_TERM     (1U << 3)
 
 extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags);
 extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
diff --git a/include/violite.h b/include/violite.h
index 8be9859ceb4..6047c7c8fd4 100644
--- a/include/violite.h
+++ b/include/violite.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2000, 2012, Oracle and/or its affiliates.
-   Copyright (c) 2012 Monty Program Ab
+   Copyright (c) 2012, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -51,9 +51,9 @@ enum enum_vio_io_event
   VIO_IO_EVENT_CONNECT
 };
 
-#define VIO_LOCALHOST 1                         /* a localhost connection */
-#define VIO_BUFFERED_READ 2                     /* use buffered read */
-#define VIO_READ_BUFFER_SIZE 16384              /* size of read buffer */
+#define VIO_LOCALHOST 1U                        /* a localhost connection */
+#define VIO_BUFFERED_READ 2U                    /* use buffered read */
+#define VIO_READ_BUFFER_SIZE 16384U             /* size of read buffer */
 #define VIO_DESCRIPTION_SIZE 30                 /* size of description */
 
 Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags);
diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c
index 4d281b98d1c..c0622cd2cbf 100644
--- a/mysys/ma_dyncol.c
+++ b/mysys/ma_dyncol.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011, 2013, Monty Program Ab
+/* Copyright (c) 2011, 2017, MariaDB Corporation.
    Copyright (c) 2011, 2012, Oleksandr Byelkin
 
    Redistribution and use in source and binary forms, with or without
@@ -74,15 +74,15 @@ uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
   2 bits which determinate size of offset in the header -1
 */
 /* mask to get above bits */
-#define DYNCOL_FLG_OFFSET   (1|2)
-#define DYNCOL_FLG_NAMES    4
-#define DYNCOL_FLG_NMOFFSET (8|16)
+#define DYNCOL_FLG_OFFSET   (1U|2U)
+#define DYNCOL_FLG_NAMES    4U
+#define DYNCOL_FLG_NMOFFSET (8U|16U)
 /**
   All known flags mask that could be set.
 
   @note DYNCOL_FLG_NMOFFSET should be 0 for now.
 */
-#define DYNCOL_FLG_KNOWN  (1|2|4)
+#define DYNCOL_FLG_KNOWN  (1U|2U|4U)
 
 /* formats */
 enum enum_dyncol_format
@@ -294,7 +294,7 @@ static void set_fixed_header_named(DYNAMIC_COLUMN *str, DYN_HEADER *hdr)
   DBUG_ASSERT(hdr->offset_size <= MAX_OFFSET_LENGTH_NM);
   /* size of data offset, named format flag, size of names offset (0 means 2) */
   str->str[0]=
-    (char) ((str->str[0] & ~(DYNCOL_FLG_OFFSET | DYNCOL_FLG_NMOFFSET)) |
+    (char) (((uchar)str->str[0] & ~(DYNCOL_FLG_OFFSET | DYNCOL_FLG_NMOFFSET)) |
             (hdr->offset_size - 2) | DYNCOL_FLG_NAMES);
   int2store(str->str + 1, hdr->column_count);        /* columns number */
   int2store(str->str + 3, hdr->nmpool_size);
@@ -319,7 +319,7 @@ static my_bool type_and_offset_store_num(uchar *place, size_t offset_size,
 {
   ulong val = (((ulong) offset) << 3) | (type - 1);
   DBUG_ASSERT(type != DYN_COL_NULL);
-  DBUG_ASSERT(((type - 1) & (~7)) == 0); /* fit in 3 bits */
+  DBUG_ASSERT(((type - 1) & (~7U)) == 0); /* fit in 3 bits */
   DBUG_ASSERT(offset_size >= 1 && offset_size <= 4);
 
   /* Index entry starts with column number; jump over it */
@@ -359,7 +359,7 @@ static my_bool type_and_offset_store_named(uchar *place, size_t offset_size,
 {
   ulonglong val = (((ulong) offset) << 4) | (type - 1);
   DBUG_ASSERT(type != DYN_COL_NULL);
-  DBUG_ASSERT(((type - 1) & (~0xf)) == 0); /* fit in 4 bits */
+  DBUG_ASSERT(((type - 1) & (~0xfU)) == 0); /* fit in 4 bits */
   DBUG_ASSERT(offset_size >= 2 && offset_size <= 5);
 
   /* Index entry starts with name offset; jump over it */
diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c
index 3077415b243..74eaa12f19d 100644
--- a/mysys/mf_keycache.c
+++ b/mysys/mf_keycache.c
@@ -1,4 +1,5 @@
 /* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
+   Copyright (c) 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -274,16 +275,16 @@ struct st_hash_link
 };
 
 /* simple states of a block */
-#define BLOCK_ERROR           1 /* an error occurred when performing file i/o */
-#define BLOCK_READ            2 /* file block is in the block buffer         */
-#define BLOCK_IN_SWITCH       4 /* block is preparing to read new page       */
-#define BLOCK_REASSIGNED      8 /* blk does not accept requests for old page */
-#define BLOCK_IN_FLUSH       16 /* block is selected for flush               */
-#define BLOCK_CHANGED        32 /* block buffer contains a dirty page        */
-#define BLOCK_IN_USE         64 /* block is not free                         */
-#define BLOCK_IN_EVICTION   128 /* block is selected for eviction            */
-#define BLOCK_IN_FLUSHWRITE 256 /* block is in write to file                 */
-#define BLOCK_FOR_UPDATE    512 /* block is selected for buffer modification */
+#define BLOCK_ERROR           1U/* an error occurred when performing file i/o */
+#define BLOCK_READ            2U/* file block is in the block buffer         */
+#define BLOCK_IN_SWITCH       4U/* block is preparing to read new page       */
+#define BLOCK_REASSIGNED      8U/* blk does not accept requests for old page */
+#define BLOCK_IN_FLUSH       16U/* block is selected for flush               */
+#define BLOCK_CHANGED        32U/* block buffer contains a dirty page        */
+#define BLOCK_IN_USE         64U/* block is not free                         */
+#define BLOCK_IN_EVICTION   128U/* block is selected for eviction            */
+#define BLOCK_IN_FLUSHWRITE 256U/* block is in write to file                 */
+#define BLOCK_FOR_UPDATE    512U/* block is selected for buffer modification */
 
 /* page status, returned by find_key_block */
 #define PAGE_READ               0
diff --git a/mysys_ssl/yassl.cc b/mysys_ssl/yassl.cc
index 9717870fe26..5146c9a9abc 100644
--- a/mysys_ssl/yassl.cc
+++ b/mysys_ssl/yassl.cc
@@ -1,5 +1,5 @@
 /*
- Copyright (c) 2015 MariaDB Corporation
+ Copyright (c) 2015, 2017, MariaDB Corporation.
 
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
@@ -27,9 +27,9 @@
 
 using yaSSL::yaERR_remove_state;
 
-#define EVP_CIPH_ECB_MODE     0x1
-#define EVP_CIPH_CBC_MODE     0x2
-#define EVP_CIPH_NO_PADDING 0x100
+#define EVP_CIPH_ECB_MODE     0x1U
+#define EVP_CIPH_CBC_MODE     0x2U
+#define EVP_CIPH_NO_PADDING 0x100U
 
 /*
   note that TaoCrypt::AES object is not explicitly put into EVP_CIPHER_CTX.
diff --git a/sql-common/my_time.c b/sql-common/my_time.c
index 88f28e1d44a..5571b87e08a 100644
--- a/sql-common/my_time.c
+++ b/sql-common/my_time.c
@@ -1,6 +1,6 @@
 /*
    Copyright (c) 2004, 2012, Oracle and/or its affiliates.
-   Copyright (c) 2010, 2013, Monty Program Ab.
+   Copyright (c) 2010, 2017, MariaDB Corporation.
 
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
@@ -1444,11 +1444,11 @@ MYSQL_TIME *unpack_time(longlong packed, MYSQL_TIME *my_time)
   if ((my_time->neg= packed < 0))
     packed= -packed;
   get_one(my_time->second_part, 1000000ULL);
-  get_one(my_time->second,           60ULL);
-  get_one(my_time->minute,           60ULL);
-  get_one(my_time->hour,             24ULL);
-  get_one(my_time->day,              32ULL);
-  get_one(my_time->month,            13ULL);
+  get_one(my_time->second,           60U);
+  get_one(my_time->minute,           60U);
+  get_one(my_time->hour,             24U);
+  get_one(my_time->day,              32U);
+  get_one(my_time->month,            13U);
   my_time->year= (uint)packed;
   my_time->time_type= MYSQL_TIMESTAMP_DATETIME;
   return my_time;
diff --git a/sql/create_options.cc b/sql/create_options.cc
index 40382c7887e..7edc2cb95f2 100644
--- a/sql/create_options.cc
+++ b/sql/create_options.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2010 Monty Program Ab
+/* Copyright (C) 2010, 2017, MariaDB Corporation Ab
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
 #include <my_getopt.h>
 #include "set_var.h"
 
-#define FRM_QUOTED_VALUE 0x8000
+#define FRM_QUOTED_VALUE 0x8000U
 
 /**
   Links this item to the given list end
diff --git a/sql/field.h b/sql/field.h
index 2dc5d91c126..d101436ff87 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1,7 +1,7 @@
 #ifndef FIELD_INCLUDED
 #define FIELD_INCLUDED
 /* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
-   Copyright (c) 2008, 2015, MariaDB
+   Copyright (c) 2008, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -1022,7 +1022,7 @@ class Field: public Value_source
   virtual int cmp_max(const uchar *a, const uchar *b, uint max_len)
     { return cmp(a, b); }
   virtual int cmp(const uchar *,const uchar *)=0;
-  virtual int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L)
+  virtual int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0U)
   { return memcmp(a,b,pack_length()); }
   virtual int cmp_offset(uint row_offset)
   { return cmp(ptr,ptr+row_offset); }
@@ -1373,7 +1373,7 @@ class Field: public Value_source
   void set_storage_type(ha_storage_media storage_type_arg)
   {
     DBUG_ASSERT(field_storage_type() == HA_SM_DEFAULT);
-    flags |= (storage_type_arg << FIELD_FLAGS_STORAGE_MEDIA);
+    flags |= uint32(storage_type_arg << FIELD_FLAGS_STORAGE_MEDIA);
   }
 
   column_format_type column_format() const
@@ -1385,7 +1385,7 @@ class Field: public Value_source
   void set_column_format(column_format_type column_format_arg)
   {
     DBUG_ASSERT(column_format() == COLUMN_FORMAT_TYPE_DEFAULT);
-    flags |= (column_format_arg << FIELD_FLAGS_COLUMN_FORMAT);
+    flags |= uint32(column_format_arg << FIELD_FLAGS_COLUMN_FORMAT);
   }
 
   /*
@@ -3134,7 +3134,7 @@ class Field_varstring :public Field_longstr {
   int cmp_max(const uchar *, const uchar *, uint max_length);
   int cmp(const uchar *a,const uchar *b)
   {
-    return cmp_max(a, b, ~0L);
+    return cmp_max(a, b, ~0U);
   }
   void sort_string(uchar *buff,uint length);
   uint get_key_image(uchar *buff,uint length, imagetype type);
@@ -3143,7 +3143,7 @@ class Field_varstring :public Field_longstr {
   virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
   virtual const uchar *unpack(uchar* to, const uchar *from,
                               const uchar *from_end, uint param_data);
-  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
+  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0U);
   int key_cmp(const uchar *,const uchar*);
   int key_cmp(const uchar *str, uint length);
   uint packed_col_length(const uchar *to, uint length);
@@ -3253,9 +3253,9 @@ class Field_blob :public Field_longstr {
   my_decimal *val_decimal(my_decimal *);
   int cmp_max(const uchar *, const uchar *, uint max_length);
   int cmp(const uchar *a,const uchar *b)
-    { return cmp_max(a, b, ~0L); }
+    { return cmp_max(a, b, ~0U); }
   int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length);
-  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
+  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0U);
   int key_cmp(const uchar *,const uchar*);
   int key_cmp(const uchar *str, uint length);
   /* Never update the value of min_val for a blob field */
@@ -3955,26 +3955,26 @@ bool check_expression(Virtual_column_info *vcol, const char *name,
   The following are for the interface with the .frm file
 */
 
-#define FIELDFLAG_DECIMAL		1
-#define FIELDFLAG_BINARY		1	// Shares same flag
-#define FIELDFLAG_NUMBER		2
-#define FIELDFLAG_ZEROFILL		4
-#define FIELDFLAG_PACK			120	// Bits used for packing
-#define FIELDFLAG_INTERVAL		256     // mangled with decimals!
-#define FIELDFLAG_BITFIELD		512	// mangled with decimals!
-#define FIELDFLAG_BLOB			1024	// mangled with decimals!
-#define FIELDFLAG_GEOM			2048    // mangled with decimals!
-
-#define FIELDFLAG_TREAT_BIT_AS_CHAR     4096    /* use Field_bit_as_char */
-#define FIELDFLAG_LONG_DECIMAL          8192
-#define FIELDFLAG_NO_DEFAULT		16384   /* sql */
-#define FIELDFLAG_MAYBE_NULL		((uint) 32768)// sql
-#define FIELDFLAG_HEX_ESCAPE		((uint) 0x10000)
+#define FIELDFLAG_DECIMAL		1U
+#define FIELDFLAG_BINARY		1U	// Shares same flag
+#define FIELDFLAG_NUMBER		2U
+#define FIELDFLAG_ZEROFILL		4U
+#define FIELDFLAG_PACK			120U	// Bits used for packing
+#define FIELDFLAG_INTERVAL		256U    // mangled with decimals!
+#define FIELDFLAG_BITFIELD		512U	// mangled with decimals!
+#define FIELDFLAG_BLOB			1024U	// mangled with decimals!
+#define FIELDFLAG_GEOM			2048U   // mangled with decimals!
+
+#define FIELDFLAG_TREAT_BIT_AS_CHAR     4096U   /* use Field_bit_as_char */
+#define FIELDFLAG_LONG_DECIMAL          8192U
+#define FIELDFLAG_NO_DEFAULT		16384U  /* sql */
+#define FIELDFLAG_MAYBE_NULL		32768U	// sql
+#define FIELDFLAG_HEX_ESCAPE		0x10000U
 #define FIELDFLAG_PACK_SHIFT		3
 #define FIELDFLAG_DEC_SHIFT		8
-#define FIELDFLAG_MAX_DEC               63
+#define FIELDFLAG_MAX_DEC               63U
 
-#define MTYP_TYPENR(type) (type & 127)	/* Remove bits from type */
+#define MTYP_TYPENR(type) (type & 127U)	/* Remove bits from type */
 
 #define f_is_dec(x)		((x) & FIELDFLAG_DECIMAL)
 #define f_is_num(x)		((x) & FIELDFLAG_NUMBER)
@@ -3988,7 +3988,7 @@ bool check_expression(Virtual_column_info *vcol, const char *name,
 #define f_is_bitfield(x)        (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
 #define f_is_blob(x)		(((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
 #define f_is_geom(x)		(((x) & (FIELDFLAG_GEOM | FIELDFLAG_NUMBER)) == FIELDFLAG_GEOM)
-#define f_settype(x)		(((int) (x)) << FIELDFLAG_PACK_SHIFT)
+#define f_settype(x)		(((uint) (x)) << FIELDFLAG_PACK_SHIFT)
 #define f_maybe_null(x)		((x) & FIELDFLAG_MAYBE_NULL)
 #define f_no_default(x)		((x) & FIELDFLAG_NO_DEFAULT)
 #define f_bit_as_char(x)        ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
diff --git a/sql/handler.h b/sql/handler.h
index 3e04cf7f7b5..1d4d95bd94a 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -2,7 +2,7 @@
 #define HANDLER_INCLUDED
 /*
    Copyright (c) 2000, 2016, Oracle and/or its affiliates.
-   Copyright (c) 2009, 2016, MariaDB
+   Copyright (c) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -236,12 +236,12 @@ enum enum_alter_inplace_result {
   @note This optimization in combination with batching may be used to
         remove even more roundtrips.
 */
-#define HA_READ_BEFORE_WRITE_REMOVAL  (1LL << 43)
+#define HA_READ_BEFORE_WRITE_REMOVAL  (1ULL << 43)
 
 /*
   Engine supports extended fulltext API
  */
-#define HA_CAN_FULLTEXT_EXT              (1LL << 44)
+#define HA_CAN_FULLTEXT_EXT              (1ULL << 44)
 
 /*
   Storage engine supports table export using the
@@ -249,7 +249,7 @@ enum enum_alter_inplace_result {
   (meaning, after this statement one can copy table files out of the
   datadir and later "import" (somehow) in another MariaDB instance)
  */
-#define HA_CAN_EXPORT                 (1LL << 45)
+#define HA_CAN_EXPORT                 (1ULL << 45)
 
 /*
   Storage engine does not require an exclusive metadata lock
@@ -259,7 +259,7 @@ enum enum_alter_inplace_result {
   read or modify the table - this is defined by THR locks and the
   ::store_lock() method).
 */
-#define HA_CONCURRENT_OPTIMIZE          (1LL << 46)
+#define HA_CONCURRENT_OPTIMIZE          (1ULL << 46)
 
 /*
   Set of all binlog flags. Currently only contain the capabilities
@@ -298,24 +298,24 @@ enum enum_alter_inplace_result {
   Partitioning needs both ADD and DROP to be supported by its underlying
   handlers, due to error handling, see bug#57778.
 */
-#define HA_INPLACE_ADD_INDEX_NO_READ_WRITE         (1L << 0)
-#define HA_INPLACE_DROP_INDEX_NO_READ_WRITE        (1L << 1)
-#define HA_INPLACE_ADD_UNIQUE_INDEX_NO_READ_WRITE  (1L << 2)
-#define HA_INPLACE_DROP_UNIQUE_INDEX_NO_READ_WRITE (1L << 3)
-#define HA_INPLACE_ADD_PK_INDEX_NO_READ_WRITE      (1L << 4)
-#define HA_INPLACE_DROP_PK_INDEX_NO_READ_WRITE     (1L << 5)
+#define HA_INPLACE_ADD_INDEX_NO_READ_WRITE         (1UL << 0)
+#define HA_INPLACE_DROP_INDEX_NO_READ_WRITE        (1UL << 1)
+#define HA_INPLACE_ADD_UNIQUE_INDEX_NO_READ_WRITE  (1UL << 2)
+#define HA_INPLACE_DROP_UNIQUE_INDEX_NO_READ_WRITE (1UL << 3)
+#define HA_INPLACE_ADD_PK_INDEX_NO_READ_WRITE      (1UL << 4)
+#define HA_INPLACE_DROP_PK_INDEX_NO_READ_WRITE     (1UL << 5)
 /*
   These are set if different kinds of indexes can be created or dropped
   in-place while still allowing concurrent reads (but not writes) of table
   data. If a handler is capable of one or more of these, it should also set
   the corresponding *_NO_READ_WRITE bit(s).
 */
-#define HA_INPLACE_ADD_INDEX_NO_WRITE              (1L << 6)
-#define HA_INPLACE_DROP_INDEX_NO_WRITE             (1L << 7)
-#define HA_INPLACE_ADD_UNIQUE_INDEX_NO_WRITE       (1L << 8)
-#define HA_INPLACE_DROP_UNIQUE_INDEX_NO_WRITE      (1L << 9)
-#define HA_INPLACE_ADD_PK_INDEX_NO_WRITE           (1L << 10)
-#define HA_INPLACE_DROP_PK_INDEX_NO_WRITE          (1L << 11)
+#define HA_INPLACE_ADD_INDEX_NO_WRITE              (1UL << 6)
+#define HA_INPLACE_DROP_INDEX_NO_WRITE             (1UL << 7)
+#define HA_INPLACE_ADD_UNIQUE_INDEX_NO_WRITE       (1UL << 8)
+#define HA_INPLACE_DROP_UNIQUE_INDEX_NO_WRITE      (1UL << 9)
+#define HA_INPLACE_ADD_PK_INDEX_NO_WRITE           (1UL << 10)
+#define HA_INPLACE_DROP_PK_INDEX_NO_WRITE          (1UL << 11)
 /*
   HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
   supported at all.
@@ -341,9 +341,9 @@ enum enum_alter_inplace_result {
   the storage engine. A typical engine to support this is NDB (through
   WL #2498).
 */
-#define HA_PARTITION_FUNCTION_SUPPORTED         (1L << 12)
-#define HA_FAST_CHANGE_PARTITION                (1L << 13)
-#define HA_PARTITION_ONE_PHASE                  (1L << 14)
+#define HA_PARTITION_FUNCTION_SUPPORTED         (1UL << 12)
+#define HA_FAST_CHANGE_PARTITION                (1UL << 13)
+#define HA_PARTITION_ONE_PHASE                  (1UL << 14)
 
 /* operations for disable/enable indexes */
 #define HA_KEY_SWITCH_NONUNIQ      0
@@ -369,25 +369,25 @@ enum enum_alter_inplace_result {
   HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
 */
 
-#define HA_OPEN_KEYFILE		1
-#define HA_READ_ONLY		16	/* File opened as readonly */
+#define HA_OPEN_KEYFILE		1U
+#define HA_READ_ONLY		16U	/* File opened as readonly */
 /* Try readonly if can't open with read and write */
-#define HA_TRY_READ_ONLY	32
+#define HA_TRY_READ_ONLY	32U
 
 	/* Some key definitions */
 #define HA_KEY_NULL_LENGTH	1
 #define HA_KEY_BLOB_LENGTH	2
 
-#define HA_LEX_CREATE_TMP_TABLE	1
-#define HA_CREATE_TMP_ALTER     8
+#define HA_LEX_CREATE_TMP_TABLE	1U
+#define HA_CREATE_TMP_ALTER     8U
 
 #define HA_MAX_REC_LENGTH	65535
 
 /* Table caching type */
 #define HA_CACHE_TBL_NONTRANSACT 0
-#define HA_CACHE_TBL_NOCACHE     1
-#define HA_CACHE_TBL_ASKTRANSACT 2
-#define HA_CACHE_TBL_TRANSACT    4
+#define HA_CACHE_TBL_NOCACHE     1U
+#define HA_CACHE_TBL_ASKTRANSACT 2U
+#define HA_CACHE_TBL_TRANSACT    4U
 
 /**
   Options for the START TRANSACTION statement.
@@ -409,9 +409,9 @@ static const uint MYSQL_START_TRANS_OPT_READ_ONLY          = 2;
 static const uint MYSQL_START_TRANS_OPT_READ_WRITE         = 4;
 
 /* Flags for method is_fatal_error */
-#define HA_CHECK_DUP_KEY 1
-#define HA_CHECK_DUP_UNIQUE 2
-#define HA_CHECK_FK_ERROR 4
+#define HA_CHECK_DUP_KEY 1U
+#define HA_CHECK_DUP_UNIQUE 2U
+#define HA_CHECK_FK_ERROR 4U
 #define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
 #define HA_CHECK_ALL (~0U)
 
@@ -478,49 +478,49 @@ enum enum_binlog_command {
 /* struct to hold information about the table that should be created */
 
 /* Bits in used_fields */
-#define HA_CREATE_USED_AUTO             (1L << 0)
-#define HA_CREATE_USED_RAID             (1L << 1) //RAID is no longer availble
-#define HA_CREATE_USED_UNION            (1L << 2)
-#define HA_CREATE_USED_INSERT_METHOD    (1L << 3)
-#define HA_CREATE_USED_MIN_ROWS         (1L << 4)
-#define HA_CREATE_USED_MAX_ROWS         (1L << 5)
-#define HA_CREATE_USED_AVG_ROW_LENGTH   (1L << 6)
-#define HA_CREATE_USED_PACK_KEYS        (1L << 7)
-#define HA_CREATE_USED_CHARSET          (1L << 8)
-#define HA_CREATE_USED_DEFAULT_CHARSET  (1L << 9)
-#define HA_CREATE_USED_DATADIR          (1L << 10)
-#define HA_CREATE_USED_INDEXDIR         (1L << 11)
-#define HA_CREATE_USED_ENGINE           (1L << 12)
-#define HA_CREATE_USED_CHECKSUM         (1L << 13)
-#define HA_CREATE_USED_DELAY_KEY_WRITE  (1L << 14)
-#define HA_CREATE_USED_ROW_FORMAT       (1L << 15)
-#define HA_CREATE_USED_COMMENT          (1L << 16)
-#define HA_CREATE_USED_PASSWORD         (1L << 17)
-#define HA_CREATE_USED_CONNECTION       (1L << 18)
-#define HA_CREATE_USED_KEY_BLOCK_SIZE   (1L << 19)
+#define HA_CREATE_USED_AUTO             (1UL << 0)
+#define HA_CREATE_USED_RAID             (1UL << 1) //RAID is no longer availble
+#define HA_CREATE_USED_UNION            (1UL << 2)
+#define HA_CREATE_USED_INSERT_METHOD    (1UL << 3)
+#define HA_CREATE_USED_MIN_ROWS         (1UL << 4)
+#define HA_CREATE_USED_MAX_ROWS         (1UL << 5)
+#define HA_CREATE_USED_AVG_ROW_LENGTH   (1UL << 6)
+#define HA_CREATE_USED_PACK_KEYS        (1UL << 7)
+#define HA_CREATE_USED_CHARSET          (1UL << 8)
+#define HA_CREATE_USED_DEFAULT_CHARSET  (1UL << 9)
+#define HA_CREATE_USED_DATADIR          (1UL << 10)
+#define HA_CREATE_USED_INDEXDIR         (1UL << 11)
+#define HA_CREATE_USED_ENGINE           (1UL << 12)
+#define HA_CREATE_USED_CHECKSUM         (1UL << 13)
+#define HA_CREATE_USED_DELAY_KEY_WRITE  (1UL << 14)
+#define HA_CREATE_USED_ROW_FORMAT       (1UL << 15)
+#define HA_CREATE_USED_COMMENT          (1UL << 16)
+#define HA_CREATE_USED_PASSWORD         (1UL << 17)
+#define HA_CREATE_USED_CONNECTION       (1UL << 18)
+#define HA_CREATE_USED_KEY_BLOCK_SIZE   (1UL << 19)
 /* The following two are used by Maria engine: */
-#define HA_CREATE_USED_TRANSACTIONAL    (1L << 20)
-#define HA_CREATE_USED_PAGE_CHECKSUM    (1L << 21)
+#define HA_CREATE_USED_TRANSACTIONAL    (1UL << 20)
+#define HA_CREATE_USED_PAGE_CHECKSUM    (1UL << 21)
 /** This is set whenever STATS_PERSISTENT=0|1|default has been
 specified in CREATE/ALTER TABLE. See also HA_OPTION_STATS_PERSISTENT in
 include/my_base.h. It is possible to distinguish whether
 STATS_PERSISTENT=default has been specified or no STATS_PERSISTENT= is
 given at all. */
-#define HA_CREATE_USED_STATS_PERSISTENT (1L << 22)
+#define HA_CREATE_USED_STATS_PERSISTENT (1UL << 22)
 /**
    This is set whenever STATS_AUTO_RECALC=0|1|default has been
    specified in CREATE/ALTER TABLE. See enum_stats_auto_recalc.
    It is possible to distinguish whether STATS_AUTO_RECALC=default
    has been specified or no STATS_AUTO_RECALC= is given at all.
 */
-#define HA_CREATE_USED_STATS_AUTO_RECALC (1L << 23)
+#define HA_CREATE_USED_STATS_AUTO_RECALC (1UL << 23)
 /**
    This is set whenever STATS_SAMPLE_PAGES=N|default has been
    specified in CREATE/ALTER TABLE. It is possible to distinguish whether
    STATS_SAMPLE_PAGES=default has been specified or no STATS_SAMPLE_PAGES= is
    given at all.
 */
-#define HA_CREATE_USED_STATS_SAMPLE_PAGES (1L << 24)
+#define HA_CREATE_USED_STATS_SAMPLE_PAGES (1UL << 24)
 
 
 /*
@@ -614,8 +614,7 @@ struct xid_t {
   }
   uint length()
   {
-    return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
-           gtrid_length+bqual_length;
+    return uint(sizeof(formatID)+key_length());
   }
   uchar *key() const
   {
@@ -623,7 +622,8 @@ struct xid_t {
   }
   uint key_length() const
   {
-    return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
+    return uint(sizeof(gtrid_length)+sizeof(bqual_length)+
+		gtrid_length+bqual_length);
   }
 };
 typedef struct xid_t XID;
@@ -2332,12 +2332,13 @@ class Cost_estimate
 
   /**
     Whether or not all costs in the object are zero
-    
+
     @return true if all costs are zero, false otherwise
   */
   bool is_zero() const
-  { 
-    return !(io_count || cpu_cost || import_cost || mem_cost);
+  {
+    return io_count == 0.0 && cpu_cost == 0.0 &&
+      import_cost == 0.0 && mem_cost == 0.0;
   }
 
   void reset()
@@ -2402,29 +2403,29 @@ void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted,
   The ranges may not use the full key but all of them will use the same number
   of key parts.
 */
-#define HA_MRR_SINGLE_POINT 1
-#define HA_MRR_FIXED_KEY  2
+#define HA_MRR_SINGLE_POINT 1U
+#define HA_MRR_FIXED_KEY  2U
 
 /* 
   Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
   'range' parameter.
 */
-#define HA_MRR_NO_ASSOCIATION 4
+#define HA_MRR_NO_ASSOCIATION 4U
 
 /* 
   The MRR user will provide ranges in key order, and MRR implementation
   must return rows in key order.
 */
-#define HA_MRR_SORTED 8
+#define HA_MRR_SORTED 8U
 
 /* MRR implementation doesn't have to retrieve full records */
-#define HA_MRR_INDEX_ONLY 16
+#define HA_MRR_INDEX_ONLY 16U
 
 /* 
   The passed memory buffer is of maximum possible size, the caller can't
   assume larger buffer.
 */
-#define HA_MRR_LIMITS 32
+#define HA_MRR_LIMITS 32U
 
 
 /*
@@ -2433,14 +2434,14 @@ void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted,
    flag. SQL layer remembers the flag value and then passes it to
    multi_read_range_init().
 */
-#define HA_MRR_USE_DEFAULT_IMPL 64
+#define HA_MRR_USE_DEFAULT_IMPL 64U
 
 /*
   Used only as parameter to multi_range_read_info():
   Flag set <=> the caller guarantees that the bounds of the scanned ranges
   will not have NULL values.
 */
-#define HA_MRR_NO_NULL_ENDPOINTS 128
+#define HA_MRR_NO_NULL_ENDPOINTS 128U
 
 /*
   The MRR user has materialized range keys somewhere in the user's buffer.
@@ -2451,7 +2452,7 @@ void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted,
   pointer in range->start_key.key will point to a key value that will remain 
   there until the end of the MRR scan.
 */
-#define HA_MRR_MATERIALIZED_KEYS 256
+#define HA_MRR_MATERIALIZED_KEYS 256U
 
 /*
   The following bits are reserved for use by MRR implementation. The intended
@@ -2469,15 +2470,15 @@ void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted,
     handler->multi_range_read_explain_info(mrr_mode) to get a text description
     of the picked MRR scan; the description will be a part of EXPLAIN output.
 */
-#define HA_MRR_IMPLEMENTATION_FLAG1 512
-#define HA_MRR_IMPLEMENTATION_FLAG2 1024
-#define HA_MRR_IMPLEMENTATION_FLAG3 2048
-#define HA_MRR_IMPLEMENTATION_FLAG4 4096
-#define HA_MRR_IMPLEMENTATION_FLAG5 8192
-#define HA_MRR_IMPLEMENTATION_FLAG6 16384
+#define HA_MRR_IMPLEMENTATION_FLAG1 512U
+#define HA_MRR_IMPLEMENTATION_FLAG2 1024U
+#define HA_MRR_IMPLEMENTATION_FLAG3 2048U
+#define HA_MRR_IMPLEMENTATION_FLAG4 4096U
+#define HA_MRR_IMPLEMENTATION_FLAG5 8192U
+#define HA_MRR_IMPLEMENTATION_FLAG6 16384U
 
 #define HA_MRR_IMPLEMENTATION_FLAGS \
-  (512 | 1024 | 2048 | 4096 | 8192 | 16384)
+  (512U | 1024U | 2048U | 4096U | 8192U | 16384U)
 
 /*
   This is a buffer area that the handler can use to store rows.
diff --git a/sql/item.h b/sql/item.h
index 27fb716e0c9..0450c94108b 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -2,7 +2,7 @@
 #define SQL_ITEM_INCLUDED
 
 /* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
-   Copyright (c) 2009, 2016, MariaDB
+   Copyright (c) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -97,10 +97,10 @@ enum precedence {
 typedef Bounds_checked_array<Item*> Ref_ptr_array;
 
 static inline uint32
-char_to_byte_length_safe(uint32 char_length_arg, uint32 mbmaxlen_arg)
+char_to_byte_length_safe(size_t char_length_arg, uint32 mbmaxlen_arg)
 {
-   ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg;
-   return (tmp > UINT_MAX32) ? (uint32) UINT_MAX32 : (uint32) tmp;
+   size_t tmp= char_length_arg * mbmaxlen_arg;
+   return (tmp > UINT_MAX32) ? UINT_MAX32 : static_cast<uint32>(tmp);
 }
 
 bool mark_unsupported_function(const char *where, void *store, uint result);
@@ -523,7 +523,7 @@ class Copy_query_with_rewrite
   bool copy_up_to(size_t bytes)
   {
     DBUG_ASSERT(bytes >= from);
-    return dst->append(src + from, bytes - from);
+    return dst->append(src + from, uint32(bytes - from));
   }
 
 public:
@@ -1835,7 +1835,7 @@ class Item: public Value_source,
     max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
     collation.collation= cs;
   }
-  void fix_char_length(uint32 max_char_length_arg)
+  void fix_char_length(size_t max_char_length_arg)
   {
     max_length= char_to_byte_length_safe(max_char_length_arg,
                                          collation.collation->mbmaxlen);
diff --git a/sql/log.cc b/sql/log.cc
index 23326532388..7ad9790bb13 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1,5 +1,5 @@
 /* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
-   Copyright (c) 2009, 2016, MariaDB
+   Copyright (c) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -646,7 +646,7 @@ void Log_to_csv_event_handler::cleanup()
 
 bool Log_to_csv_event_handler::
   log_general(THD *thd, my_hrtime_t event_time, const char *user_host,
-              uint user_host_len, int thread_id_arg,
+              uint user_host_len, my_thread_id thread_id_arg,
               const char *command_type, uint command_type_len,
               const char *sql_text, uint sql_text_len,
               CHARSET_INFO *client_cs)
@@ -1056,7 +1056,7 @@ bool Log_to_file_event_handler::
 
 bool Log_to_file_event_handler::
   log_general(THD *thd, my_hrtime_t event_time, const char *user_host,
-              uint user_host_len, int thread_id_arg,
+              uint user_host_len, my_thread_id thread_id_arg,
               const char *command_type, uint command_type_len,
               const char *sql_text, uint sql_text_len,
               CHARSET_INFO *client_cs)
@@ -2850,12 +2850,11 @@ void MYSQL_QUERY_LOG::reopen_file()
 */
 
 bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host,
-                            uint user_host_len, int thread_id_arg,
+                            uint user_host_len, my_thread_id thread_id_arg,
                             const char *command_type, uint command_type_len,
                             const char *sql_text, uint sql_text_len)
 {
   char buff[32];
-  uint length= 0;
   char local_time_buff[MAX_TIME_SIZE];
   struct tm start;
   uint time_buff_len= 0;
@@ -2889,7 +2888,7 @@ bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host,
           goto err;
 
       /* command_type, thread_id */
-      length= my_snprintf(buff, 32, "%5ld ", (long) thread_id_arg);
+      size_t length= my_snprintf(buff, 32, "%5llu ", thread_id_arg);
 
     if (my_b_write(&log_file, (uchar*) buff, length))
       goto err;
@@ -2973,7 +2972,7 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
     int tmp_errno= 0;
     char buff[80], *end;
     char query_time_buff[22+7], lock_time_buff[22+7];
-    uint buff_len;
+    size_t buff_len;
     end= buff;
 
     if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
@@ -10244,8 +10243,8 @@ IO_CACHE * get_trans_log(THD * thd)
   if (cache_mngr)
     return cache_mngr->get_binlog_cache_log(true);
 
-  WSREP_DEBUG("binlog cache not initialized, conn: %lld",
-              (longlong) thd->thread_id);
+  WSREP_DEBUG("binlog cache not initialized, conn: %llu",
+	      thd->thread_id);
   return NULL;
 }
 
@@ -10283,8 +10282,8 @@ void thd_binlog_trx_reset(THD * thd)
 
 void thd_binlog_rollback_stmt(THD * thd)
 {
-  WSREP_DEBUG("thd_binlog_rollback_stmt connection: %lld",
-              (longlong) thd->thread_id);
+  WSREP_DEBUG("thd_binlog_rollback_stmt connection: %llu",
+	      thd->thread_id);
   binlog_cache_mngr *const cache_mngr=
     (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
   if (cache_mngr)
diff --git a/sql/log.h b/sql/log.h
index 8ddf8641cfa..f1a025edfb9 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2005, 2016, Oracle and/or its affiliates.
-   Copyright (c) 2009, 2016, Monty Program Ab
+   Copyright (c) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -287,9 +287,9 @@ typedef struct st_log_info
 #define MAX_LOG_HANDLERS_NUM 3
 
 /* log event handler flags */
-#define LOG_NONE       1
-#define LOG_FILE       2
-#define LOG_TABLE      4
+#define LOG_NONE       1U
+#define LOG_FILE       2U
+#define LOG_TABLE      4U
 
 class Log_event;
 class Rows_log_event;
@@ -355,7 +355,7 @@ class MYSQL_QUERY_LOG: public MYSQL_LOG
   MYSQL_QUERY_LOG() : last_time(0) {}
   void reopen_file();
   bool write(time_t event_time, const char *user_host,
-             uint user_host_len, int thread_id,
+             uint user_host_len, my_thread_id thread_id,
              const char *command_type, uint command_type_len,
              const char *sql_text, uint sql_text_len);
   bool write(THD *thd, time_t current_time,
@@ -907,7 +907,7 @@ class Log_event_handler
   virtual bool log_error(enum loglevel level, const char *format,
                          va_list args)= 0;
   virtual bool log_general(THD *thd, my_hrtime_t event_time, const char *user_host,
-                           uint user_host_len, int thread_id,
+                           uint user_host_len, my_thread_id thread_id,
                            const char *command_type, uint command_type_len,
                            const char *sql_text, uint sql_text_len,
                            CHARSET_INFO *client_cs)= 0;
@@ -936,7 +936,7 @@ class Log_to_csv_event_handler: public Log_event_handler
   virtual bool log_error(enum loglevel level, const char *format,
                          va_list args);
   virtual bool log_general(THD *thd, my_hrtime_t event_time, const char *user_host,
-                           uint user_host_len, int thread_id,
+                           uint user_host_len, my_thread_id thread_id,
                            const char *command_type, uint command_type_len,
                            const char *sql_text, uint sql_text_len,
                            CHARSET_INFO *client_cs);
@@ -968,7 +968,7 @@ class Log_to_file_event_handler: public Log_event_handler
   virtual bool log_error(enum loglevel level, const char *format,
                          va_list args);
   virtual bool log_general(THD *thd, my_hrtime_t event_time, const char *user_host,
-                           uint user_host_len, int thread_id,
+                           uint user_host_len, my_thread_id thread_id,
                            const char *command_type, uint command_type_len,
                            const char *sql_text, uint sql_text_len,
                            CHARSET_INFO *client_cs);
diff --git a/sql/log_event.h b/sql/log_event.h
index c2829a9bb10..5689d36aea8 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2000, 2014, Oracle and/or its affiliates.
-   Copyright (c) 2009, 2014, Monty Program Ab.
+   Copyright (c) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -828,7 +828,7 @@ typedef struct st_print_event_info
   char time_zone_str[MAX_TIME_ZONE_NAME_LENGTH];
   uint lc_time_names_number;
   uint charset_database_number;
-  uint thread_id;
+  my_thread_id thread_id;
   bool thread_id_printed;
   uint32 server_id;
   bool server_id_printed;
@@ -2008,7 +2008,7 @@ class Query_log_event: public Log_event
   uint32 q_len;
   uint32 db_len;
   uint16 error_code;
-  ulong thread_id;
+  my_thread_id thread_id;
   /*
     For events created by Query_log_event::do_apply_event (and
     Load_log_event::do_apply_event()) we need the *original* thread
@@ -2435,7 +2435,7 @@ class Load_log_event: public Log_event
   void print_query(THD *thd, bool need_db, const char *cs, String *buf,
                    my_off_t *fn_start, my_off_t *fn_end,
                    const char *qualify_db);
-  ulong thread_id;
+  my_thread_id thread_id;
   ulong slave_proxy_id;
   uint32 table_name_len;
   /*
diff --git a/sql/log_slow.h b/sql/log_slow.h
index 3ae2060cc27..c641d2be87d 100644
--- a/sql/log_slow.h
+++ b/sql/log_slow.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2009 Monty Program Ab
+/* Copyright (C) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -16,23 +16,22 @@
 /* Defining what to log to slow log */
 
 #define LOG_SLOW_VERBOSITY_INIT           0
-#define LOG_SLOW_VERBOSITY_INNODB         (1 << 0)
-#define LOG_SLOW_VERBOSITY_QUERY_PLAN     (1 << 1)
-#define LOG_SLOW_VERBOSITY_EXPLAIN        (1 << 2)
+#define LOG_SLOW_VERBOSITY_INNODB         (1U << 0)
+#define LOG_SLOW_VERBOSITY_QUERY_PLAN     (1U << 1)
+#define LOG_SLOW_VERBOSITY_EXPLAIN        (1U << 2)
 
 #define QPLAN_INIT            QPLAN_QC_NO
 
-#define QPLAN_ADMIN           (1 << 0)
-#define QPLAN_FILESORT        (1 << 1)
-#define QPLAN_FILESORT_DISK   (1 << 2)
-#define QPLAN_FULL_JOIN       (1 << 3)
-#define QPLAN_FULL_SCAN       (1 << 4)
-#define QPLAN_QC              (1 << 5)
-#define QPLAN_QC_NO           (1 << 6)
-#define QPLAN_TMP_DISK        (1 << 7)
-#define QPLAN_TMP_TABLE       (1 << 8)
-#define QPLAN_FILESORT_PRIORITY_QUEUE       (1 << 9)
+#define QPLAN_ADMIN           (1U << 0)
+#define QPLAN_FILESORT        (1U << 1)
+#define QPLAN_FILESORT_DISK   (1U << 2)
+#define QPLAN_FULL_JOIN       (1U << 3)
+#define QPLAN_FULL_SCAN       (1U << 4)
+#define QPLAN_QC              (1U << 5)
+#define QPLAN_QC_NO           (1U << 6)
+#define QPLAN_TMP_DISK        (1U << 7)
+#define QPLAN_TMP_TABLE       (1U << 8)
+#define QPLAN_FILESORT_PRIORITY_QUEUE       (1U << 9)
 
 /* ... */
-#define QPLAN_MAX             (((ulong) 1) << 31) /* reserved as placeholder */
-
+#define QPLAN_MAX             (1UL << 31) /* reserved as placeholder */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 57292603b2d..7b8e3ee0ee6 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -8770,7 +8770,7 @@ static int mysql_init_variables(void)
   mysql_home_ptr= mysql_home;
   log_error_file_ptr= log_error_file;
   protocol_version= PROTOCOL_VERSION;
-  what_to_log= ~ (1L << (uint) COM_TIME);
+  what_to_log= ~(1UL << COM_TIME);
   denied_connections= 0;
   executed_events= 0;
   global_query_id= 1;
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 9022b8cef03..8f74194181a 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2006, 2016, Oracle and/or its affiliates.
-   Copyright (c) 2010, 2016, MariaDB
+   Copyright (c) 2010, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -49,16 +49,16 @@ typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
 #endif
 
 	/* Bits from testflag */
-#define TEST_PRINT_CACHED_TABLES 1
-#define TEST_NO_KEY_GROUP	 2
-#define TEST_MIT_THREAD		4
-#define TEST_BLOCKING		8
-#define TEST_KEEP_TMP_TABLES	16
-#define TEST_READCHECK		64	/**< Force use of readcheck */
-#define TEST_NO_EXTRA		128
-#define TEST_CORE_ON_SIGNAL	256	/**< Give core if signal */
-#define TEST_SIGINT		1024	/**< Allow sigint on threads */
-#define TEST_SYNCHRONIZATION    2048    /**< get server to do sleep in
+#define TEST_PRINT_CACHED_TABLES 1U
+#define TEST_NO_KEY_GROUP	 2U
+#define TEST_MIT_THREAD		4U
+#define TEST_BLOCKING		8U
+#define TEST_KEEP_TMP_TABLES	16U
+#define TEST_READCHECK		64U	/**< Force use of readcheck */
+#define TEST_NO_EXTRA		128U
+#define TEST_CORE_ON_SIGNAL	256U	/**< Give core if signal */
+#define TEST_SIGINT		1024U	/**< Allow sigint on threads */
+#define TEST_SYNCHRONIZATION    2048U   /**< get server to do sleep in
                                            some places */
 
 /* Keep things compatible */
@@ -721,7 +721,7 @@ inline query_id_t get_query_id()
 /* increment global_thread_id and return it.  */
 inline __attribute__((warn_unused_result)) my_thread_id next_thread_id()
 {
-  return my_atomic_add64_explicit(&global_thread_id, 1, MY_MEMORY_ORDER_RELAXED);
+  return my_atomic_add64_explicit((int64*) &global_thread_id, 1, MY_MEMORY_ORDER_RELAXED);
 }
 
 #if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
diff --git a/sql/session_tracker.h b/sql/session_tracker.h
index 3f73b5dc705..0caf08b4027 100644
--- a/sql/session_tracker.h
+++ b/sql/session_tracker.h
@@ -2,7 +2,7 @@
 #define SESSION_TRACKER_INCLUDED
 
 /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
-   Copyright (c) 2016, MariaDB
+   Copyright (c) 2016, 2017, MariaDB Corporation. All Rights Reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -280,7 +280,7 @@ class Transaction_state_tracker : public State_tracker
 
   inline void update_change_flags(THD *thd)
   {
-    tx_changed &= ~TX_CHG_STATE;
+    tx_changed &= uint(~TX_CHG_STATE);
     tx_changed |= (tx_curr_state != tx_reported_state) ? TX_CHG_STATE : 0;
     if (tx_changed != TX_CHG_NONE)
       mark_as_changed(thd, NULL);
diff --git a/sql/sql_acl.h b/sql/sql_acl.h
index be206b1f86f..765035cde74 100644
--- a/sql/sql_acl.h
+++ b/sql/sql_acl.h
@@ -2,6 +2,7 @@
 #define SQL_ACL_INCLUDED
 
 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,35 +21,35 @@
 #include "violite.h"                            /* SSL_type */
 #include "sql_class.h"                          /* LEX_COLUMN */
 
-#define SELECT_ACL      (1L << 0)
-#define INSERT_ACL      (1L << 1)
-#define UPDATE_ACL      (1L << 2)
-#define DELETE_ACL      (1L << 3)
-#define CREATE_ACL      (1L << 4)
-#define DROP_ACL        (1L << 5)
-#define RELOAD_ACL      (1L << 6)
-#define SHUTDOWN_ACL    (1L << 7)
-#define PROCESS_ACL     (1L << 8)
-#define FILE_ACL        (1L << 9)
-#define GRANT_ACL       (1L << 10)
-#define REFERENCES_ACL  (1L << 11)
-#define INDEX_ACL       (1L << 12)
-#define ALTER_ACL       (1L << 13)
-#define SHOW_DB_ACL     (1L << 14)
-#define SUPER_ACL       (1L << 15)
-#define CREATE_TMP_ACL  (1L << 16)
-#define LOCK_TABLES_ACL (1L << 17)
-#define EXECUTE_ACL     (1L << 18)
-#define REPL_SLAVE_ACL  (1L << 19)
-#define REPL_CLIENT_ACL (1L << 20)
-#define CREATE_VIEW_ACL (1L << 21)
-#define SHOW_VIEW_ACL   (1L << 22)
-#define CREATE_PROC_ACL (1L << 23)
-#define ALTER_PROC_ACL  (1L << 24)
-#define CREATE_USER_ACL (1L << 25)
-#define EVENT_ACL       (1L << 26)
-#define TRIGGER_ACL     (1L << 27)
-#define CREATE_TABLESPACE_ACL (1L << 28)
+#define SELECT_ACL      (1UL << 0)
+#define INSERT_ACL      (1UL << 1)
+#define UPDATE_ACL      (1UL << 2)
+#define DELETE_ACL      (1UL << 3)
+#define CREATE_ACL      (1UL << 4)
+#define DROP_ACL        (1UL << 5)
+#define RELOAD_ACL      (1UL << 6)
+#define SHUTDOWN_ACL    (1UL << 7)
+#define PROCESS_ACL     (1UL << 8)
+#define FILE_ACL        (1UL << 9)
+#define GRANT_ACL       (1UL << 10)
+#define REFERENCES_ACL  (1UL << 11)
+#define INDEX_ACL       (1UL << 12)
+#define ALTER_ACL       (1UL << 13)
+#define SHOW_DB_ACL     (1UL << 14)
+#define SUPER_ACL       (1UL << 15)
+#define CREATE_TMP_ACL  (1UL << 16)
+#define LOCK_TABLES_ACL (1UL << 17)
+#define EXECUTE_ACL     (1UL << 18)
+#define REPL_SLAVE_ACL  (1UL << 19)
+#define REPL_CLIENT_ACL (1UL << 20)
+#define CREATE_VIEW_ACL (1UL << 21)
+#define SHOW_VIEW_ACL   (1UL << 22)
+#define CREATE_PROC_ACL (1UL << 23)
+#define ALTER_PROC_ACL  (1UL << 24)
+#define CREATE_USER_ACL (1UL << 25)
+#define EVENT_ACL       (1UL << 26)
+#define TRIGGER_ACL     (1UL << 27)
+#define CREATE_TABLESPACE_ACL (1UL << 28)
 /*
   don't forget to update
   1. static struct show_privileges_st sys_privileges[]
@@ -57,7 +58,7 @@
   4. acl_init() or whatever - to define behaviour for old privilege tables
   5. sql_yacc.yy - for GRANT/REVOKE to work
 */
-#define NO_ACCESS       (1L << 30)
+#define NO_ACCESS       (1UL << 30)
 #define DB_ACLS \
 (UPDATE_ACL | SELECT_ACL | INSERT_ACL | DELETE_ACL | CREATE_ACL | DROP_ACL | \
  GRANT_ACL | REFERENCES_ACL | INDEX_ACL | ALTER_ACL | CREATE_TMP_ACL | \
diff --git a/sql/sql_audit.h b/sql/sql_audit.h
index d6f670538cd..5f530c676c3 100644
--- a/sql/sql_audit.h
+++ b/sql/sql_audit.h
@@ -2,6 +2,7 @@
 #define SQL_AUDIT_INCLUDED
 
 /* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -160,7 +161,7 @@ void mysql_audit_general(THD *thd, uint event_subtype,
       event.general_user_length= make_user_name(thd, user_buff);
       event.general_thread_id= (unsigned long)thd->thread_id;
       event.general_query= thd->query_string.str();
-      event.general_query_length= thd->query_string.length();
+      event.general_query_length= (unsigned) thd->query_string.length();
       event.general_charset= thd->query_string.charset();
       event.general_rows= thd->get_stmt_da()->current_row_for_warning();
       event.database= thd->db;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index ffdd63f1f4c..22895d7a2d8 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1,6 +1,6 @@
 /*
    Copyright (c) 2000, 2016, Oracle and/or its affiliates.
-   Copyright (c) 2009, 2016, MariaDB
+   Copyright (c) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -179,7 +179,7 @@ class CSET_STRING
   }
 
   inline char *str() const { return string.str; }
-  inline uint32 length() const { return string.length; }
+  inline size_t length() const { return string.length; }
   CHARSET_INFO *charset() const { return cs; }
 
   friend LEX_STRING * thd_query_string (MYSQL_THD thd);
@@ -1068,7 +1068,10 @@ class Statement: public ilink, public Query_arena
 
 
   inline char *query() const { return query_string.str(); }
-  inline uint32 query_length() const { return query_string.length(); }
+  inline uint32 query_length() const
+  {
+    return static_cast<uint32>(query_string.length());
+  }
   CHARSET_INFO *query_charset() const { return query_string.charset(); }
   void set_query_inner(const CSET_STRING &string_arg)
   {
diff --git a/sql/sql_error.h b/sql/sql_error.h
index aa8e6c6b0f3..6ba1f043b2b 100644
--- a/sql/sql_error.h
+++ b/sql/sql_error.h
@@ -1,4 +1,5 @@
 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -50,7 +51,7 @@ class Sql_condition : public Sql_alloc
     Convert a bitmask consisting of MYSQL_TIME_{NOTE|WARN}_XXX bits
     to WARN_LEVEL_XXX
   */
-  static enum_warning_level time_warn_level(int warnings)
+  static enum_warning_level time_warn_level(uint warnings)
   {
     return MYSQL_TIME_WARN_HAVE_WARNINGS(warnings) ?
            WARN_LEVEL_WARN : WARN_LEVEL_NOTE;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 4a87ca095c4..3b45b1ad40c 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
-   Copyright (c) 2010, 2016, MariaDB
+   Copyright (c) 2010, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -1497,8 +1497,8 @@ class Query_tables_list
     This has all flags from 0 (inclusive) to BINLOG_STMT_FLAG_COUNT
     (exclusive) set.
   */
-  static const int BINLOG_STMT_UNSAFE_ALL_FLAGS=
-    ((1 << BINLOG_STMT_UNSAFE_COUNT) - 1);
+  static const uint32 BINLOG_STMT_UNSAFE_ALL_FLAGS=
+    ((1U << BINLOG_STMT_UNSAFE_COUNT) - 1);
 
   /**
     Maps elements of enum_binlog_stmt_unsafe to error codes.
diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h
index 9a0acea1d18..7b89246a9f9 100644
--- a/sql/sql_plugin.h
+++ b/sql/sql_plugin.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2005, 2012, Oracle and/or its affiliates.
-   Copyright (c) 2009, 2012, Monty Program Ab
+   Copyright (c) 2009, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -53,9 +53,9 @@ extern ulong dlopen_count;
 /*
   the following flags are valid for plugin_init()
 */
-#define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
-#define PLUGIN_INIT_SKIP_PLUGIN_TABLE    2
-#define PLUGIN_INIT_SKIP_INITIALIZATION  4
+#define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1U
+#define PLUGIN_INIT_SKIP_PLUGIN_TABLE    2U
+#define PLUGIN_INIT_SKIP_INITIALIZATION  4U
 
 #define INITIAL_LEX_PLUGIN_LIST_SIZE    16
 
@@ -71,12 +71,12 @@ typedef struct st_mysql_show_var SHOW_VAR;
   It's a bitmap, because it makes it easier to test
   "whether the state is one of those..."
 */
-#define PLUGIN_IS_FREED         1
-#define PLUGIN_IS_DELETED       2
-#define PLUGIN_IS_UNINITIALIZED 4
-#define PLUGIN_IS_READY         8
-#define PLUGIN_IS_DYING         16
-#define PLUGIN_IS_DISABLED      32
+#define PLUGIN_IS_FREED         1U
+#define PLUGIN_IS_DELETED       2U
+#define PLUGIN_IS_UNINITIALIZED 4U
+#define PLUGIN_IS_READY         8U
+#define PLUGIN_IS_DYING         16U
+#define PLUGIN_IS_DISABLED      32U
 
 struct st_ptr_backup {
   void **ptr;
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 76cded43128..0d4570fbe47 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -2,7 +2,7 @@
 #define SQL_SELECT_INCLUDED
 
 /* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
-   Copyright (c) 2008, 2015, MariaDB
+   Copyright (c) 2008, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -36,9 +36,9 @@
 
 typedef struct st_join_table JOIN_TAB;
 /* Values in optimize */
-#define KEY_OPTIMIZE_EXISTS		1
-#define KEY_OPTIMIZE_REF_OR_NULL	2
-#define KEY_OPTIMIZE_EQ	                4
+#define KEY_OPTIMIZE_EXISTS		1U
+#define KEY_OPTIMIZE_REF_OR_NULL	2U
+#define KEY_OPTIMIZE_EQ	                4U
 
 inline uint get_hash_join_key_no() { return MAX_KEY; }
 
@@ -178,10 +178,10 @@ enum sj_strategy_enum
 };
 
 /* Values for JOIN_TAB::packed_info */
-#define TAB_INFO_HAVE_VALUE 1
-#define TAB_INFO_USING_INDEX 2
-#define TAB_INFO_USING_WHERE 4
-#define TAB_INFO_FULL_SCAN_ON_NULL 8
+#define TAB_INFO_HAVE_VALUE 1U
+#define TAB_INFO_USING_INDEX 2U
+#define TAB_INFO_USING_WHERE 4U
+#define TAB_INFO_FULL_SCAN_ON_NULL 8U
 
 typedef enum_nested_loop_state
 (*Next_select_func)(JOIN *, struct st_join_table *, bool);
diff --git a/sql/sql_string.h b/sql/sql_string.h
index 4b70675dca4..18f5f4cac5c 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -3,7 +3,7 @@
 
 /*
    Copyright (c) 2000, 2013, Oracle and/or its affiliates.
-   Copyright (c) 2008, 2013, Monty Program Ab.
+   Copyright (c) 2008, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -97,9 +97,9 @@ class String_copier: public String_copy_status,
     Convert a string between character sets.
     "dstcs" and "srccs" cannot be &my_charset_bin.
   */
-  uint convert_fix(CHARSET_INFO *dstcs, char *dst, uint dst_length,
-                   CHARSET_INFO *srccs, const char *src, uint src_length,
-                   uint nchars)
+  size_t convert_fix(CHARSET_INFO *dstcs, char *dst, uint dst_length,
+                     CHARSET_INFO *srccs, const char *src, uint src_length,
+                     uint nchars)
   {
     return my_convert_fix(dstcs, dst, dst_length,
                           srccs, src, src_length, nchars, this, this);
@@ -673,7 +673,7 @@ class String
   {
     DBUG_ASSERT(Alloced_length >= (str_length + net_length_size(length)));
     char *pos= (char *) net_store_length((uchar *)(Ptr + str_length), length);
-    str_length= pos - Ptr;
+    str_length= uint32(pos - Ptr);
   }
   void q_net_store_data(const uchar *from, size_t length)
   {
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index eac61052284..07af3b891ea 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1,6 +1,6 @@
 /*
    Copyright (c) 2000, 2016, Oracle and/or its affiliates.
-   Copyright (c) 2010, 2016, MariaDB
+   Copyright (c) 2010, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -2888,7 +2888,7 @@ void calculate_interval_lengths(CHARSET_INFO *cs, TYPELIB *interval,
 
 int prepare_create_field(Column_definition *sql_field,
 			 uint *blob_columns, 
-			 longlong table_flags)
+			 ulonglong table_flags)
 {
   uint dup_val_count;
   uint decimals= sql_field->decimals;
diff --git a/sql/sql_table.h b/sql/sql_table.h
index 628c51f678f..5abb25d1ea5 100644
--- a/sql/sql_table.h
+++ b/sql/sql_table.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2006, 2014, Oracle and/or its affiliates.
-   Copyright (c) 2011, 2014, Monty Program Ab.
+   Copyright (c) 2011, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -254,7 +254,7 @@ void close_cached_table(THD *thd, TABLE *table);
 void sp_prepare_create_field(THD *thd, Column_definition *sql_field);
 int prepare_create_field(Column_definition *sql_field,
 			 uint *blob_columns,
-			 longlong table_flags);
+			 ulonglong table_flags);
 CHARSET_INFO* get_sql_field_charset(Create_field *sql_field,
                                     HA_CREATE_INFO *create_info);
 bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags);
diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h
index afe47fb36f4..9d1c79cc7cf 100644
--- a/sql/sql_trigger.h
+++ b/sql/sql_trigger.h
@@ -3,6 +3,7 @@
 
 /*
    Copyright (c) 2004, 2011, Oracle and/or its affiliates.
+   Copyright (c) 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -273,8 +274,8 @@ class Table_triggers_list: public Sql_alloc
   Field **nullable_fields() { return record0_field; }
   void reset_extra_null_bitmap()
   {
-    int null_bytes= (trigger_table->s->stored_fields -
-                     trigger_table->s->null_fields + 7)/8;
+    size_t null_bytes= (trigger_table->s->stored_fields -
+                        trigger_table->s->null_fields + 7)/8;
     bzero(extra_null_bitmap, null_bytes);
   }
 
diff --git a/sql/structs.h b/sql/structs.h
index ea47d6255de..81e9aad66d6 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -2,6 +2,7 @@
 #define STRUCTS_INCLUDED
 
 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -331,26 +332,26 @@ typedef struct st_index_stats
 
 
 	/* Bits in form->update */
-#define REG_MAKE_DUPP		1	/* Make a copy of record when read */
-#define REG_NEW_RECORD		2	/* Write a new record if not found */
-#define REG_UPDATE		4	/* Uppdate record */
-#define REG_DELETE		8	/* Delete found record */
-#define REG_PROG		16	/* User is updating database */
-#define REG_CLEAR_AFTER_WRITE	32
-#define REG_MAY_BE_UPDATED	64
-#define REG_AUTO_UPDATE		64	/* Used in D-forms for scroll-tables */
-#define REG_OVERWRITE		128
-#define REG_SKIP_DUP		256
+#define REG_MAKE_DUPP		1U	/* Make a copy of record when read */
+#define REG_NEW_RECORD		2U	/* Write a new record if not found */
+#define REG_UPDATE		4U	/* Uppdate record */
+#define REG_DELETE		8U	/* Delete found record */
+#define REG_PROG		16U	/* User is updating database */
+#define REG_CLEAR_AFTER_WRITE	32U
+#define REG_MAY_BE_UPDATED	64U
+#define REG_AUTO_UPDATE		64U	/* Used in D-forms for scroll-tables */
+#define REG_OVERWRITE		128U
+#define REG_SKIP_DUP		256U
 
 	/* Bits in form->status */
-#define STATUS_NO_RECORD	(1+2)	/* Record isn't usably */
-#define STATUS_GARBAGE		1
-#define STATUS_NOT_FOUND	2	/* No record in database when needed */
-#define STATUS_NO_PARENT	4	/* Parent record wasn't found */
-#define STATUS_NOT_READ		8	/* Record isn't read */
-#define STATUS_UPDATED		16	/* Record is updated by formula */
-#define STATUS_NULL_ROW		32	/* table->null_row is set */
-#define STATUS_DELETED		64
+#define STATUS_NO_RECORD	(1U+2U)	/* Record isn't usable */
+#define STATUS_GARBAGE		1U
+#define STATUS_NOT_FOUND	2U	/* No record in database when needed */
+#define STATUS_NO_PARENT	4U	/* Parent record wasn't found */
+#define STATUS_NOT_READ		8U	/* Record isn't read */
+#define STATUS_UPDATED		16U	/* Record is updated by formula */
+#define STATUS_NULL_ROW		32U	/* table->null_row is set */
+#define STATUS_DELETED		64U
 
 /*
   Such interval is "discrete": it is the set of
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 40cdd84a292..9a9e920c6dd 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -2465,7 +2465,7 @@ static Sys_var_uint Sys_protocol_version(
        "protocol_version",
        "The version of the client/server protocol used by the MySQL server",
        READ_ONLY GLOBAL_VAR(protocol_version), CMD_LINE_HELP_ONLY,
-       VALID_RANGE(0, ~0), DEFAULT(PROTOCOL_VERSION), BLOCK_SIZE(1));
+       VALID_RANGE(0, ~0U), DEFAULT(PROTOCOL_VERSION), BLOCK_SIZE(1));
 
 static Sys_var_proxy_user Sys_proxy_user(
        "proxy_user", "The proxy user account name used when logging in",
diff --git a/sql/table.h b/sql/table.h
index ec33188b688..f9b6ac4ae22 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -2,7 +2,7 @@
 #define TABLE_INCLUDED
 /* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
    Copyright (c) 2009, 2014, SkySQL Ab.
-   Copyright (c) 2016, MariaDB Corporation
+   Copyright (c) 2016, 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -1500,13 +1500,13 @@ typedef struct st_foreign_key_info
 
 LEX_CSTRING *fk_option_name(enum_fk_option opt);
 
-#define MY_I_S_MAYBE_NULL 1
-#define MY_I_S_UNSIGNED   2
+#define MY_I_S_MAYBE_NULL 1U
+#define MY_I_S_UNSIGNED   2U
 
 
-#define SKIP_OPEN_TABLE 0                // do not open table
-#define OPEN_FRM_ONLY   1                // open FRM file only
-#define OPEN_FULL_TABLE 2                // open FRM,MYD, MYI files
+#define SKIP_OPEN_TABLE 0U               // do not open table
+#define OPEN_FRM_ONLY   1U               // open FRM file only
+#define OPEN_FULL_TABLE 2U               // open FRM,MYD, MYI files
 
 typedef struct st_field_info
 {
@@ -1570,27 +1570,27 @@ class IS_table_read_plan;
   Types of derived tables. The ending part is a bitmap of phases that are
   applicable to a derived table of the type.
 */
-#define DTYPE_ALGORITHM_UNDEFINED    0
-#define DTYPE_VIEW                   1
-#define DTYPE_TABLE                  2
-#define DTYPE_MERGE                  4
-#define DTYPE_MATERIALIZE            8
-#define DTYPE_MULTITABLE             16
-#define DTYPE_MASK                   19
+#define DTYPE_ALGORITHM_UNDEFINED    0U
+#define DTYPE_VIEW                   1U
+#define DTYPE_TABLE                  2U
+#define DTYPE_MERGE                  4U
+#define DTYPE_MATERIALIZE            8U
+#define DTYPE_MULTITABLE             16U
+#define DTYPE_MASK                   (DTYPE_VIEW|DTYPE_TABLE|DTYPE_MULTITABLE)
 
 /*
   Phases of derived tables/views handling, see sql_derived.cc
   Values are used as parts of a bitmap attached to derived table types.
 */
-#define DT_INIT             1
-#define DT_PREPARE          2
-#define DT_OPTIMIZE         4
-#define DT_MERGE            8
-#define DT_MERGE_FOR_INSERT 16
-#define DT_CREATE           32
-#define DT_FILL             64
-#define DT_REINIT           128
-#define DT_PHASES           8
+#define DT_INIT             1U
+#define DT_PREPARE          2U
+#define DT_OPTIMIZE         4U
+#define DT_MERGE            8U
+#define DT_MERGE_FOR_INSERT 16U
+#define DT_CREATE           32U
+#define DT_FILL             64U
+#define DT_REINIT           128U
+#define DT_PHASES           8U
 /* Phases that are applicable to all derived tables. */
 #define DT_COMMON       (DT_INIT + DT_PREPARE + DT_REINIT + DT_OPTIMIZE)
 /* Phases that are applicable only to materialized derived tables. */
@@ -1610,13 +1610,13 @@ class IS_table_read_plan;
   representation for backward compatibility.
 */
 
-#define VIEW_ALGORITHM_UNDEFINED_FRM  0
-#define VIEW_ALGORITHM_MERGE_FRM      1
-#define VIEW_ALGORITHM_TMPTABLE_FRM   2
+#define VIEW_ALGORITHM_UNDEFINED_FRM  0U
+#define VIEW_ALGORITHM_MERGE_FRM      1U
+#define VIEW_ALGORITHM_TMPTABLE_FRM   2U
 
-#define JOIN_TYPE_LEFT	1
-#define JOIN_TYPE_RIGHT	2
-#define JOIN_TYPE_OUTER 4	/* Marker that this is an outer join */
+#define JOIN_TYPE_LEFT	1U
+#define JOIN_TYPE_RIGHT	2U
+#define JOIN_TYPE_OUTER 4U	/* Marker that this is an outer join */
 
 #define VIEW_SUID_INVOKER               0
 #define VIEW_SUID_DEFINER               1
diff --git a/storage/connect/blkfil.cpp b/storage/connect/blkfil.cpp
index 1f5a1a27ae5..50535d20a3d 100644
--- a/storage/connect/blkfil.cpp
+++ b/storage/connect/blkfil.cpp
@@ -412,7 +412,7 @@ void BLKFILMR2::MakeValueBitmap(void)
   Void = !Bmp[N];          // There are no good values in the file
 
   for (i = 0; i < N; i++) {
-    Bxp[i] = ~0;
+    Bxp[i] = ~0U;
 
     if (noteq)
       Bmp[i] = Bxp[i];
@@ -708,7 +708,7 @@ void BLKFILIN2::MakeValueBitmap(void)
   Void = !Bmp[N];          // There are no good values in the file
 
   for (i = 0; i < N; i++) {
-    Bxp[i] = ~0;
+    Bxp[i] = ~0U;
 
     if (noteq) {
       Bmp[i] = Bxp[i];
@@ -828,7 +828,7 @@ BLKFILIN2::BLKFILIN2(PGLOBAL g, PTDBDOS tdbp, int op, int opm, PXOB *xp)
         Bxp[i] |= btp;
 
       for (N = i--; i >= 0; i--)
-        Bxp[i] = ~0;
+        Bxp[i] = ~0U;
 
       break;
       } // endif Bmp
diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc
index 4bebb9ee7dd..49ac63cff6d 100644
--- a/storage/innobase/btr/btr0btr.cc
+++ b/storage/innobase/btr/btr0btr.cc
@@ -2,7 +2,7 @@
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2012, Facebook Inc.
-Copyright (c) 2014, 2016, MariaDB Corporation
+Copyright (c) 2014, 2017, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -725,7 +725,7 @@ btr_page_free_low(
 			offsets = rec_get_offsets(rec, index,
 						  offsets, ULINT_UNDEFINED,
 						  &heap);
-			uint size = rec_offs_data_size(offsets);
+			ulint size = rec_offs_data_size(offsets);
 			memset(rec, 0, size);
 			rec = page_rec_get_next(rec);
 			cnt++;
@@ -890,7 +890,7 @@ btr_page_get_father_node_ptr_func(
 	ulint		latch_mode,/*!< in: BTR_CONT_MODIFY_TREE
 				or BTR_CONT_SEARCH_TREE */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr)	/*!< in: mtr */
 {
 	dtuple_t*	tuple;
@@ -2396,7 +2396,7 @@ btr_insert_on_non_leaf_level_func(
 	ulint		level,	/*!< in: level, must be > 0 */
 	dtuple_t*	tuple,	/*!< in: the record to be inserted */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr)	/*!< in: mtr */
 {
 	big_rec_t*	dummy_big_rec;
diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc
index 0abc930c11d..06b5b66c2aa 100644
--- a/storage/innobase/btr/btr0cur.cc
+++ b/storage/innobase/btr/btr0cur.cc
@@ -148,7 +148,7 @@ can be released by page reorganize, then it is reorganized */
 @param not_empty table not empty
 @return estimated table wide stats from sampled value */
 #define BTR_TABLE_STATS_FROM_SAMPLE(value, index, sample, ext_size, not_empty) \
-	(((value) * static_cast<int64_t>(index->stat_n_leaf_pages) \
+	(((value) * static_cast<ib_uint64_t>(index->stat_n_leaf_pages) \
 	  + (sample) - 1 + (ext_size) + (not_empty)) / ((sample) + (ext_size)))
 
 /* @} */
@@ -414,7 +414,7 @@ btr_cur_optimistic_latch_leaves(
 	ulint*		latch_mode,
 	btr_cur_t*	cursor,
 	const char*	file,
-	ulint		line,
+	unsigned	line,
 	mtr_t*		mtr)
 {
 	ulint		mode;
@@ -747,7 +747,7 @@ btr_cur_search_to_nth_level(
 				caller currently has on search system:
 				RW_S_LATCH, or 0 */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr,	/*!< in: mtr */
 	ib_uint64_t	autoinc)/*!< in: PAGE_ROOT_AUTO_INC to be written
 				(0 if none) */
@@ -2042,7 +2042,7 @@ btr_cur_open_at_index_side_func(
 	ulint		level,		/*!< in: level to search for
 					(0=leaf). */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr)		/*!< in/out: mini-transaction */
 {
 	page_cur_t*	page_cursor;
@@ -2414,7 +2414,7 @@ btr_cur_open_at_rnd_pos_func(
 	ulint		latch_mode,	/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_cur_t*	cursor,		/*!< in/out: B-tree cursor */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
 	page_cur_t*	page_cursor;
@@ -3623,7 +3623,7 @@ btr_cur_update_in_place(
 	ut_ad(dict_index_is_online_ddl(index) == !!(flags & BTR_CREATE_FLAG)
 	      || dict_index_is_clust(index));
 	ut_ad(thr_get_trx(thr)->id == trx_id
-	      || (flags & ~(BTR_KEEP_POS_FLAG | BTR_KEEP_IBUF_BITMAP))
+	      || (flags & ulint(~(BTR_KEEP_POS_FLAG | BTR_KEEP_IBUF_BITMAP)))
 	      == (BTR_NO_UNDO_LOG_FLAG | BTR_NO_LOCKING_FLAG
 		  | BTR_CREATE_FLAG | BTR_KEEP_SYS_FLAG));
 	ut_ad(fil_page_index_page_check(btr_cur_get_page(cursor)));
@@ -3790,7 +3790,7 @@ btr_cur_optimistic_update(
 	ut_ad(dict_index_is_online_ddl(index) == !!(flags & BTR_CREATE_FLAG)
 	      || dict_index_is_clust(index));
 	ut_ad(thr_get_trx(thr)->id == trx_id
-	      || (flags & ~(BTR_KEEP_POS_FLAG | BTR_KEEP_IBUF_BITMAP))
+	      || (flags & ulint(~(BTR_KEEP_POS_FLAG | BTR_KEEP_IBUF_BITMAP)))
 	      == (BTR_NO_UNDO_LOG_FLAG | BTR_NO_LOCKING_FLAG
 		  | BTR_CREATE_FLAG | BTR_KEEP_SYS_FLAG));
 	ut_ad(fil_page_index_page_check(page));
@@ -4123,7 +4123,7 @@ btr_cur_pessimistic_update(
 	ut_ad(dict_index_is_online_ddl(index) == !!(flags & BTR_CREATE_FLAG)
 	      || dict_index_is_clust(index));
 	ut_ad(thr_get_trx(thr)->id == trx_id
-	      || (flags & ~BTR_KEEP_POS_FLAG)
+	      || (flags & ulint(~BTR_KEEP_POS_FLAG))
 	      == (BTR_NO_UNDO_LOG_FLAG | BTR_NO_LOCKING_FLAG
 		  | BTR_CREATE_FLAG | BTR_KEEP_SYS_FLAG));
 
@@ -6231,12 +6231,12 @@ btr_cur_set_ownership_of_extern_field(
 	byte_val = mach_read_from_1(data + local_len + BTR_EXTERN_LEN);
 
 	if (val) {
-		byte_val = byte_val & (~BTR_EXTERN_OWNER_FLAG);
+		byte_val &= ~BTR_EXTERN_OWNER_FLAG;
 	} else {
 #if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
 		ut_a(!(byte_val & BTR_EXTERN_OWNER_FLAG));
 #endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
-		byte_val = byte_val | BTR_EXTERN_OWNER_FLAG;
+		byte_val |= BTR_EXTERN_OWNER_FLAG;
 	}
 
 	if (page_zip) {
diff --git a/storage/innobase/btr/btr0defragment.cc b/storage/innobase/btr/btr0defragment.cc
index 7f06aed9ff0..2a6f531c006 100644
--- a/storage/innobase/btr/btr0defragment.cc
+++ b/storage/innobase/btr/btr0defragment.cc
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (C) 2013, 2014 Facebook, Inc. All Rights Reserved.
-Copyright (C) 2014, 2016, MariaDB Corporation. All Rights Reserved.
+Copyright (C) 2014, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -696,8 +696,8 @@ btr_defragment_n_pages(
 			     (data_size_per_rec
 			      * srv_defragment_fill_factor_n_recs));
 	optimal_page_size -= reserved_space;
-	n_new_slots = (total_data_size + optimal_page_size - 1)
-		      / optimal_page_size;
+	n_new_slots = uint((total_data_size + optimal_page_size - 1)
+			   / optimal_page_size);
 	if (n_new_slots >= n_pages) {
 		/* Can't defragment. */
 		if (end_of_index)
diff --git a/storage/innobase/btr/btr0pcur.cc b/storage/innobase/btr/btr0pcur.cc
index ecf3f7c07cb..741f16e0df4 100644
--- a/storage/innobase/btr/btr0pcur.cc
+++ b/storage/innobase/btr/btr0pcur.cc
@@ -229,7 +229,7 @@ btr_pcur_restore_position_func(
 	ulint		latch_mode,	/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_pcur_t*	cursor,		/*!< in: detached persistent cursor */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
 	dict_index_t*	index;
@@ -586,7 +586,7 @@ btr_pcur_open_on_user_rec_func(
 	btr_pcur_t*	cursor,		/*!< in: memory buffer for persistent
 					cursor */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
 	btr_pcur_open_low(index, 0, tuple, mode, latch_mode, cursor,
diff --git a/storage/innobase/btr/btr0scrub.cc b/storage/innobase/btr/btr0scrub.cc
index 8051c517e3a..e2670521cf3 100644
--- a/storage/innobase/btr/btr0scrub.cc
+++ b/storage/innobase/btr/btr0scrub.cc
@@ -254,11 +254,10 @@ btr_page_needs_scrubbing(
 		return BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE;
 	}
 
-	page_t*	page = buf_block_get_frame(block);
-	uint type = fil_page_get_type(page);
+	const page_t*	page = buf_block_get_frame(block);
 
 	if (allocated == BTR_SCRUB_PAGE_ALLOCATED) {
-		if (type != FIL_PAGE_INDEX) {
+		if (fil_page_get_type(page) != FIL_PAGE_INDEX) {
 			/* this function is called from fil-crypt-threads.
 			* these threads iterate all pages of all tablespaces
 			* and don't know about fil_page_type.
@@ -275,7 +274,7 @@ btr_page_needs_scrubbing(
 			return BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE;
 		}
 
-		if (page_has_garbage(page) == false) {
+		if (!page_has_garbage(page)) {
 			/* no garbage (from deleted/shrunken records) */
 			return BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE;
 		}
@@ -283,11 +282,12 @@ btr_page_needs_scrubbing(
 	} else if (allocated == BTR_SCRUB_PAGE_FREE ||
 		   allocated == BTR_SCRUB_PAGE_ALLOCATION_UNKNOWN) {
 
-		if (! (type == FIL_PAGE_INDEX ||
-		       type == FIL_PAGE_TYPE_BLOB ||
-		       type == FIL_PAGE_TYPE_ZBLOB ||
-		       type == FIL_PAGE_TYPE_ZBLOB2)) {
-
+		switch (fil_page_get_type(page)) {
+		case FIL_PAGE_INDEX:
+		case FIL_PAGE_TYPE_ZBLOB:
+		case FIL_PAGE_TYPE_ZBLOB2:
+			break;
+		default:
 			/**
 			* If this is a dropped page, we also need to scrub
 			* BLOB pages
@@ -299,7 +299,8 @@ btr_page_needs_scrubbing(
 		}
 	}
 
-	if (btr_page_get_index_id(page) == IBUF_INDEX_ID) {
+	if (block->page.id.space() == TRX_SYS_SPACE
+	    && btr_page_get_index_id(page) == IBUF_INDEX_ID) {
 		/* skip ibuf */
 		return BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE;
 	}
diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc
index d777e2abc4d..83d2346ecd2 100644
--- a/storage/innobase/btr/btr0sea.cc
+++ b/storage/innobase/btr/btr0sea.cc
@@ -2,6 +2,7 @@
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 Portions of this file contain modifications contributed and copyrighted by
 Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -1547,9 +1548,9 @@ btr_search_build_page_hash_index(
 
 	block->n_hash_helps = 0;
 
-	block->curr_n_fields = n_fields;
-	block->curr_n_bytes = n_bytes;
-	block->curr_left_side = left_side;
+	block->curr_n_fields = unsigned(n_fields);
+	block->curr_n_bytes = unsigned(n_bytes);
+	block->curr_left_side = unsigned(left_side);
 	block->index = index;
 
 	for (i = 0; i < n_cached; i++) {
diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc
index b3c11c62929..a1827e7b3b5 100644
--- a/storage/innobase/buf/buf0buf.cc
+++ b/storage/innobase/buf/buf0buf.cc
@@ -1954,7 +1954,8 @@ buf_pool_init_instance(
 	buf_pool->watch = (buf_page_t*) ut_zalloc_nokey(
 		sizeof(*buf_pool->watch) * BUF_POOL_WATCH_SIZE);
 	for (i = 0; i < BUF_POOL_WATCH_SIZE; i++) {
-		buf_pool->watch[i].buf_pool_index = buf_pool->instance_no;
+		buf_pool->watch[i].buf_pool_index
+			= unsigned(buf_pool->instance_no);
 	}
 
 	/* All fields are initialized by ut_zalloc_nokey(). */
@@ -4212,7 +4213,7 @@ buf_page_get_gen(
 	buf_block_t*		guess,
 	ulint			mode,
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	mtr_t*			mtr,
 	dberr_t*		err)
 {
@@ -4882,7 +4883,7 @@ buf_page_optimistic_get(
 	buf_block_t*	block,	/*!< in: guessed buffer block */
 	ib_uint64_t	modify_clock,/*!< in: modify clock value */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr)	/*!< in: mini-transaction */
 {
 	buf_pool_t*	buf_pool;
@@ -5002,7 +5003,7 @@ buf_page_get_known_nowait(
 	buf_block_t*	block,	/*!< in: the known page */
 	ulint		mode,	/*!< in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr)	/*!< in: mini-transaction */
 {
 	buf_pool_t*	buf_pool;
@@ -5110,7 +5111,7 @@ buf_block_t*
 buf_page_try_get_func(
 	const page_id_t&	page_id,
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	mtr_t*			mtr)
 {
 	buf_block_t*	block;
@@ -7468,7 +7469,8 @@ buf_page_encrypt_before_write(
 					      page_size,
 					      dst_frame);
 
-		ulint key_version = mach_read_from_4(dst_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
+		uint32_t key_version = mach_read_from_4(
+			dst_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
 		ut_ad(key_version == 0 || key_version >= bpage->key_version);
 		bpage->key_version = key_version;
 		bpage->real_size = page_size.physical();
diff --git a/storage/innobase/data/data0data.cc b/storage/innobase/data/data0data.cc
index 0ccf5868d14..6fe6bf648a9 100644
--- a/storage/innobase/data/data0data.cc
+++ b/storage/innobase/data/data0data.cc
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -728,7 +729,7 @@ dtuple_convert_big_rec(
 			DEBUG_SYNC_C("ib_mv_nonupdated_column_offpage");
 
 			upd_field_t	upd_field;
-			upd_field.field_no = longest_i;
+			upd_field.field_no = unsigned(longest_i);
 			upd_field.orig_len = 0;
 			upd_field.exp = NULL;
 			upd_field.old_v_val = NULL;
diff --git a/storage/innobase/data/data0type.cc b/storage/innobase/data/data0type.cc
index cad165d1489..3344f445ab8 100644
--- a/storage/innobase/data/data0type.cc
+++ b/storage/innobase/data/data0type.cc
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -140,23 +141,6 @@ dtype_is_non_binary_string_type(
 }
 
 /*********************************************************************//**
-Forms a precise type from the < 4.1.2 format precise type plus the
-charset-collation code.
- at return precise type, including the charset-collation code */
-ulint
-dtype_form_prtype(
-/*==============*/
-	ulint	old_prtype,	/*!< in: the MySQL type code and the flags
-				DATA_BINARY_TYPE etc. */
-	ulint	charset_coll)	/*!< in: MySQL charset-collation code */
-{
-	ut_a(old_prtype < 256 * 256);
-	ut_a(charset_coll <= MAX_CHAR_COLL_NUM);
-
-	return(old_prtype + (charset_coll << 16));
-}
-
-/*********************************************************************//**
 Validates a data type structure.
 @return TRUE if ok */
 ibool
diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc
index 491f29067a8..32c1a12ec1e 100644
--- a/storage/innobase/dict/dict0dict.cc
+++ b/storage/innobase/dict/dict0dict.cc
@@ -264,13 +264,11 @@ dict_get_db_name_len(
 	return(s - name);
 }
 
-/********************************************************************//**
-Reserves the dictionary system mutex for MySQL. */
+/** Reserve the dictionary system mutex. */
 void
-dict_mutex_enter_for_mysql_func(const char * file, ulint line)
-/*============================*/
+dict_mutex_enter_for_mysql_func(const char *file, unsigned line)
 {
-	mutex_enter(&dict_sys->mutex);
+	mutex_enter_loc(&dict_sys->mutex, file, line);
 }
 
 /********************************************************************//**
@@ -1316,7 +1314,7 @@ void
 dict_table_add_to_cache(
 /*====================*/
 	dict_table_t*	table,		/*!< in: table */
-	ibool		can_be_evicted,	/*!< in: TRUE if can be evicted */
+	bool		can_be_evicted,	/*!< in: whether can be evicted */
 	mem_heap_t*	heap)		/*!< in: temporary heap */
 {
 	ulint	fold;
@@ -2615,7 +2613,7 @@ dict_index_add_to_cache_w_vcol(
 	new_index->search_info = btr_search_info_create(new_index->heap);
 #endif /* BTR_CUR_ADAPT */
 
-	new_index->page = page_no;
+	new_index->page = unsigned(page_no);
 	rw_lock_create(index_tree_rw_lock_key, &new_index->lock,
 		       SYNC_INDEX_TREE);
 
@@ -3179,7 +3177,7 @@ dict_index_build_internal_clust(
 		can theoretically occur. Check for it. */
 		fixed_size += new_index->trx_id_offset;
 
-		new_index->trx_id_offset = fixed_size;
+		new_index->trx_id_offset = unsigned(fixed_size);
 
 		if (new_index->trx_id_offset != fixed_size) {
 			/* Overflow. Pretend that this is a
diff --git a/storage/innobase/dict/dict0load.cc b/storage/innobase/dict/dict0load.cc
index db14983cd8f..203185d55a5 100644
--- a/storage/innobase/dict/dict0load.cc
+++ b/storage/innobase/dict/dict0load.cc
@@ -1822,8 +1822,8 @@ dict_load_field_low(
 {
 	const byte*	field;
 	ulint		len;
-	ulint		pos_and_prefix_len;
-	ulint		prefix_len;
+	unsigned	pos_and_prefix_len;
+	unsigned	prefix_len;
 	ibool		first_field;
 	ulint		position;
 
@@ -2027,7 +2027,7 @@ dict_load_index_low(
 	ulint		n_fields;
 	ulint		type;
 	ulint		space;
-	ulint		merge_threshold;
+	unsigned	merge_threshold;
 
 	if (allocate) {
 		/* If allocate=TRUE, no dict_index_t will
diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc
index 9463c5103ca..7420b4463bb 100644
--- a/storage/innobase/dict/dict0mem.cc
+++ b/storage/innobase/dict/dict0mem.cc
@@ -2,6 +2,7 @@
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2012, Facebook Inc.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -1114,12 +1115,12 @@ dict_mem_table_is_system(
 	/* table has the following format: database/table
 	and some system table are of the form SYS_* */
 	if (strchr(name, '/')) {
-		int table_len = strlen(name);
+		size_t table_len = strlen(name);
 		const char *system_db;
 		int i = 0;
 		while ((system_db = innobase_system_databases[i++])
 			&& (system_db != NullS)) {
-			int len = strlen(system_db);
+			size_t len = strlen(system_db);
 			if (table_len > len && !strncmp(name, system_db, len)) {
 				return true;
 			}
diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc
index ac1978f2673..ccec6191ed4 100644
--- a/storage/innobase/fil/fil0crypt.cc
+++ b/storage/innobase/fil/fil0crypt.cc
@@ -1727,7 +1727,7 @@ fil_crypt_get_page_throttle_func(
 	mtr_t*			mtr,		/*!< in/out: minitransaction */
 	ulint*			sleeptime_ms,	/*!< out: sleep time */
 	const char*		file,		/*!< in: file name */
-	ulint 			line)		/*!< in: file line */
+	unsigned		line)		/*!< in: file line */
 {
 	const page_id_t&	page_id = page_id_t(space, offset);
 	dberr_t			err = DB_SUCCESS;
diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc
index 1ef209ed0ed..5a7a33f67e3 100644
--- a/storage/innobase/fil/fil0fil.cc
+++ b/storage/innobase/fil/fil0fil.cc
@@ -584,7 +584,9 @@ fil_node_open_file(
 	read_only_mode = !fsp_is_system_temporary(space->id)
 		&& srv_read_only_mode;
 
-	if (node->size == 0
+	const bool first_time_open = node->size == 0;
+
+	if (first_time_open
 	    || (space->purpose == FIL_TYPE_TABLESPACE
 		&& node == UT_LIST_GET_FIRST(space->chain)
 		&& !undo::Truncate::was_tablespace_truncated(space->id)
@@ -689,7 +691,7 @@ fil_node_open_file(
 		space->free_limit = free_limit;
 		space->free_len = free_len;
 
-		if (node->size == 0) {
+		if (first_time_open) {
 			ulint	extent_size;
 
 			extent_size = psize * FSP_EXTENT_SIZE;
@@ -727,24 +729,21 @@ fil_node_open_file(
 			innodb_data_file_key, node->name, OS_FILE_OPEN,
 			OS_FILE_AIO, OS_DATA_FILE, read_only_mode, &success);
 
-                if (!space->atomic_write_tested)
-                {
-                  const page_size_t page_size(space->flags);
-
-                  space->atomic_write_tested= 1;
-                  /*
-                    Atomic writes is supported if the file can be used
-                    with atomic_writes (not log file), O_DIRECT is
-                    used (tested in ha_innodbc.cc) and the file is
-                    device and file system that supports atomic writes
-                    for the given block size
-                  */
-                  space->atomic_write_supported=
-                    srv_use_atomic_writes &&
-                    node->atomic_write &&
-                    my_test_if_atomic_write(node->handle,
-                                            page_size.physical()) ?
-                    true : false;
+                if (first_time_open) {
+			/*
+			Atomic writes is supported if the file can be used
+			with atomic_writes (not log file), O_DIRECT is
+			used (tested in ha_innodb.cc) and the file is
+			device and file system that supports atomic writes
+			for the given block size
+			*/
+			space->atomic_write_supported
+				= srv_use_atomic_writes
+				&& node->atomic_write
+				&& my_test_if_atomic_write(
+					node->handle,
+					int(page_size_t(space->flags)
+					    .physical()));
                 }
         }
 
@@ -1302,7 +1301,7 @@ fil_mutex_enter_and_prepare_for_io(
 			}
 		}
 
-		if (ulint size = UNIV_UNLIKELY(space->recv_size)) {
+		if (ulint size = ulint(UNIV_UNLIKELY(space->recv_size))) {
 			ut_ad(node);
 			bool	success;
 			if (fil_space_extend_must_retry(space, node, size,
diff --git a/storage/innobase/fil/fil0pagecompress.cc b/storage/innobase/fil/fil0pagecompress.cc
index 18f95c94d75..1eb9ec37f5d 100644
--- a/storage/innobase/fil/fil0pagecompress.cc
+++ b/storage/innobase/fil/fil0pagecompress.cc
@@ -99,7 +99,7 @@ fil_compress_page(
 	byte*	lzo_mem)	/*!< in: temporal memory used by LZO */
 {
 	int err = Z_OK;
-	int comp_level = level;
+	int comp_level = int(level);
 	ulint header_len = FIL_PAGE_DATA + FIL_PAGE_COMPRESSED_SIZE;
 	ulint write_size=0;
 	/* Cache to avoid change during function execution */
diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc
index 6128fe54ecc..80a2aa211db 100644
--- a/storage/innobase/fsp/fsp0fsp.cc
+++ b/storage/innobase/fsp/fsp0fsp.cc
@@ -3755,7 +3755,7 @@ fsp_page_is_free_func(
 	ulint		page_no,	/*!< in: page offset */
 	mtr_t*		mtr,		/*!< in/out: mini-transaction */
 	const char *file,
-	ulint line)
+	unsigned line)
 {
 	ut_ad(mtr);
 
diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc
index 122d99dee8f..f23065ae3c7 100644
--- a/storage/innobase/gis/gis0sea.cc
+++ b/storage/innobase/gis/gis0sea.cc
@@ -542,7 +542,7 @@ rtr_pcur_open_low(
 	ulint		latch_mode,/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_pcur_t*	cursor, /*!< in: memory buffer for persistent cursor */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr)	/*!< in: mtr */
 {
 	btr_cur_t*	btr_cursor;
@@ -718,7 +718,7 @@ rtr_page_get_father_node_ptr_func(
 				out: cursor on node pointer record,
 				its page x-latched */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr)	/*!< in: mtr */
 {
 	dtuple_t*	tuple;
@@ -1262,7 +1262,7 @@ rtr_cur_restore_position_func(
 	btr_cur_t*	btr_cur,	/*!< in: detached persistent cursor */
 	ulint		level,		/*!< in: index level */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
 	dict_index_t*	index;
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index b9caea017ab..8f1e7657d1d 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -640,25 +640,6 @@ static PSI_file_info	all_innodb_files[] = {
 # endif /* UNIV_PFS_IO */
 #endif /* HAVE_PSI_INTERFACE */
 
-/******************************************************************//**
-Debug function used to read a MBR data */
-
-#ifdef UNIV_DEBUG
-void
-srv_mbr_debug(const byte* data)
-{
-	double a, b, c , d;
-	a = mach_double_read(data);
-	data += sizeof(double);
-	b = mach_double_read(data);
-	data += sizeof(double);
-	c = mach_double_read(data);
-	data += sizeof(double);
-	d = mach_double_read(data);
-	ut_ad(a && b && c &&d);
-}
-#endif
-
 static void innodb_remember_check_sysvar_funcs();
 mysql_var_check_func check_sysvar_enum;
 
@@ -4338,8 +4319,8 @@ innobase_init(
 			" It will be removed in MariaDB 10.3.";
 	}
 
-	srv_use_atomic_writes = (ibool) (innobase_use_atomic_writes &&
-                                         my_may_have_atomic_write);
+	srv_use_atomic_writes
+		= innobase_use_atomic_writes && my_may_have_atomic_write;
         if (srv_use_atomic_writes && !srv_file_per_table)
         {
           fprintf(stderr, "InnoDB: Disabling atomic_writes as file_per_table is not used.\n");
@@ -10069,7 +10050,7 @@ ha_innobase::innobase_get_index(
 					    << " InnoDB name " << index->name()
 					    << " for table " << m_prebuilt->table->name.m_name;
 
-				for(ulint i=0; i < table->s->keys; i++) {
+				for(uint i=0; i < table->s->keys; i++) {
 					index = innobase_index_lookup(m_share, i);
 					key = table->key_info + keynr;
 
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 726f641ef5a..82fa4b724f4 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -5019,7 +5019,7 @@ prepare_inplace_alter_table_dict(
 				ctx->prebuilt->trx->mysql_thd)
 				? DB_SUCCESS : DB_ERROR;
 			ctx->new_table->fts->fts_status
-				&= ~TABLE_DICT_LOCKED;
+				&= ulint(~TABLE_DICT_LOCKED);
 
 			if (error != DB_SUCCESS) {
 				goto error_handling;
diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc
index bc35f772af1..dd43a52ae66 100644
--- a/storage/innobase/handler/i_s.cc
+++ b/storage/innobase/handler/i_s.cc
@@ -950,8 +950,7 @@ fill_innodb_locks_from_cache(
 					       strlen(row->lock_table),
 					       thd);
 		OK(fields[IDX_LOCK_TABLE]->store(
-			buf, static_cast<size_t>(bufend - buf),
-			system_charset_info));
+			buf, uint(bufend - buf), system_charset_info));
 
 		/* lock_index */
 		if (row->lock_index != NULL) {
@@ -2594,7 +2593,7 @@ i_s_metrics_fill(
 		} else if (!(monitor_info->monitor_type & MONITOR_NO_AVERAGE)
 			   && !(monitor_info->monitor_type
 				& MONITOR_DISPLAY_CURRENT)) {
-			if (time_diff) {
+			if (time_diff != 0) {
 				OK(fields[METRIC_AVG_VALUE_START]->store(
 					(double) MONITOR_VALUE_SINCE_START(
 						count) / time_diff));
@@ -2619,7 +2618,7 @@ i_s_metrics_fill(
 				time_diff = 0;
 			}
 
-			if (time_diff) {
+			if (time_diff != 0) {
 				OK(fields[METRIC_AVG_VALUE_RESET]->store(
 					static_cast<double>(
 						MONITOR_VALUE(count) / time_diff)));
@@ -4931,7 +4930,7 @@ i_s_innodb_buffer_page_fill(
 
 				OK(fields[IDX_BUFFER_PAGE_TABLE_NAME]->store(
 					table_name,
-					static_cast<size_t>(table_name_end - table_name),
+					uint(table_name_end - table_name),
 					system_charset_info));
 				fields[IDX_BUFFER_PAGE_TABLE_NAME]->set_notnull();
 
@@ -5053,7 +5052,7 @@ i_s_innodb_set_page_type(
 			page_info->page_type = I_S_PAGE_TYPE_INDEX;
 		}
 
-		page_info->data_size = (ulint)(page_header_get_field(
+		page_info->data_size = unsigned(page_header_get_field(
 			page, PAGE_HEAP_TOP) - (page_is_comp(page)
 						? PAGE_NEW_SUPREMUM_END
 						: PAGE_OLD_SUPREMUM_END)
@@ -5651,7 +5650,7 @@ i_s_innodb_buf_page_lru_fill(
 
 				OK(fields[IDX_BUF_LRU_PAGE_TABLE_NAME]->store(
 					table_name,
-					static_cast<size_t>(table_name_end - table_name),
+					uint(table_name_end - table_name),
 					system_charset_info));
 				fields[IDX_BUF_LRU_PAGE_TABLE_NAME]->set_notnull();
 
@@ -9155,7 +9154,8 @@ i_s_innodb_mutexes_fill_table(
 
 		OK(field_store_string(fields[MUTEXES_NAME], mutex->cmutex_name));
 		OK(field_store_string(fields[MUTEXES_CREATE_FILE], innobase_basename(mutex->cfile_name)));
-		OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], mutex->cline));
+		OK(fields[MUTEXES_CREATE_LINE]->store(mutex->cline, true));
+		fields[MUTEXES_CREATE_LINE]->set_notnull();
 		OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)mutex->count_os_wait));
 		OK(schema_table_store_record(thd, tables->table));
 	}
@@ -9168,7 +9168,8 @@ i_s_innodb_mutexes_fill_table(
 
 		OK(field_store_string(fields[MUTEXES_NAME], block_mutex->cmutex_name));
 		OK(field_store_string(fields[MUTEXES_CREATE_FILE], buf1));
-		OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], block_mutex->cline));
+		OK(fields[MUTEXES_CREATE_LINE]->store(block_mutex->cline, true));
+		fields[MUTEXES_CREATE_LINE]->set_notnull();
 		OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)block_mutex_oswait_count));
 		OK(schema_table_store_record(thd, tables->table));
 	}
@@ -9192,7 +9193,8 @@ i_s_innodb_mutexes_fill_table(
 
 		//OK(field_store_string(fields[MUTEXES_NAME], lock->lock_name));
 		OK(field_store_string(fields[MUTEXES_CREATE_FILE], innobase_basename(lock->cfile_name)));
-		OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], lock->cline));
+		OK(fields[MUTEXES_CREATE_LINE]->store(lock->cline, true));
+		fields[MUTEXES_CREATE_LINE]->set_notnull();
 		OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)lock->count_os_wait));
 		OK(schema_table_store_record(thd, tables->table));
 	}
@@ -9205,7 +9207,8 @@ i_s_innodb_mutexes_fill_table(
 
 		//OK(field_store_string(fields[MUTEXES_NAME], block_lock->lock_name));
 		OK(field_store_string(fields[MUTEXES_CREATE_FILE], buf1));
-		OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], block_lock->cline));
+		OK(fields[MUTEXES_CREATE_LINE]->store(block_lock->cline, true));
+		fields[MUTEXES_CREATE_LINE]->set_notnull();
 		OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)block_lock_oswait_count));
 		OK(schema_table_store_record(thd, tables->table));
 	}
diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc
index cf3ce487607..3bc56c2d737 100644
--- a/storage/innobase/ibuf/ibuf0ibuf.cc
+++ b/storage/innobase/ibuf/ibuf0ibuf.cc
@@ -810,7 +810,7 @@ ibuf_bitmap_get_map_page_func(
 	const page_id_t&	page_id,
 	const page_size_t&	page_size,
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	mtr_t*			mtr)
 {
 	buf_block_t*	block = NULL;
@@ -1138,7 +1138,7 @@ ibuf_page_low(
 	ibool			x_latch,
 #endif /* UNIV_DEBUG */
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	mtr_t*			mtr)
 {
 	ibool	ret;
diff --git a/storage/innobase/include/btr0btr.h b/storage/innobase/include/btr0btr.h
index 419c5db657d..c226687f0b1 100644
--- a/storage/innobase/include/btr0btr.h
+++ b/storage/innobase/include/btr0btr.h
@@ -2,7 +2,7 @@
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2012, Facebook Inc.
-Copyright (c) 2014, 2016, MariaDB Corporation. All Rights Reserved.
+Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -79,66 +79,66 @@ enum btr_latch_mode {
 /** If this is ORed to btr_latch_mode, it means that the search tuple
 will be inserted to the index, at the searched position.
 When the record is not in the buffer pool, try to use the insert buffer. */
-#define BTR_INSERT		512
+#define BTR_INSERT		512U
 
 /** This flag ORed to btr_latch_mode says that we do the search in query
 optimization */
-#define BTR_ESTIMATE		1024
+#define BTR_ESTIMATE		1024U
 
 /** This flag ORed to BTR_INSERT says that we can ignore possible
 UNIQUE definition on secondary indexes when we decide if we can use
 the insert buffer to speed up inserts */
-#define BTR_IGNORE_SEC_UNIQUE	2048
+#define BTR_IGNORE_SEC_UNIQUE	2048U
 
 /** Try to delete mark the record at the searched position using the
 insert/delete buffer when the record is not in the buffer pool. */
-#define BTR_DELETE_MARK		4096
+#define BTR_DELETE_MARK		4096U
 
 /** Try to purge the record at the searched position using the insert/delete
 buffer when the record is not in the buffer pool. */
-#define BTR_DELETE		8192
+#define BTR_DELETE		8192U
 
 /** In the case of BTR_SEARCH_LEAF or BTR_MODIFY_LEAF, the caller is
 already holding an S latch on the index tree */
-#define BTR_ALREADY_S_LATCHED	16384
+#define BTR_ALREADY_S_LATCHED	16384U
 
 /** In the case of BTR_MODIFY_TREE, the caller specifies the intention
 to insert record only. It is used to optimize block->lock range.*/
-#define BTR_LATCH_FOR_INSERT	32768
+#define BTR_LATCH_FOR_INSERT	32768U
 
 /** In the case of BTR_MODIFY_TREE, the caller specifies the intention
 to delete record only. It is used to optimize block->lock range.*/
-#define BTR_LATCH_FOR_DELETE	65536
+#define BTR_LATCH_FOR_DELETE	65536U
 
 /** This flag is for undo insert of rtree. For rtree, we need this flag
 to find proper rec to undo insert.*/
-#define BTR_RTREE_UNDO_INS	131072
+#define BTR_RTREE_UNDO_INS	131072U
 
 /** In the case of BTR_MODIFY_LEAF, the caller intends to allocate or
 free the pages of externally stored fields. */
-#define BTR_MODIFY_EXTERNAL	262144
+#define BTR_MODIFY_EXTERNAL	262144U
 
 /** Try to delete mark the record at the searched position when the
 record is in spatial index */
-#define BTR_RTREE_DELETE_MARK	524288
-
-#define BTR_LATCH_MODE_WITHOUT_FLAGS(latch_mode)	\
-	((latch_mode) & ~(BTR_INSERT			\
-			  | BTR_DELETE_MARK		\
-			  | BTR_RTREE_UNDO_INS		\
-			  | BTR_RTREE_DELETE_MARK	\
-			  | BTR_DELETE			\
-			  | BTR_ESTIMATE		\
-			  | BTR_IGNORE_SEC_UNIQUE	\
-			  | BTR_ALREADY_S_LATCHED	\
-			  | BTR_LATCH_FOR_INSERT	\
-			  | BTR_LATCH_FOR_DELETE	\
-			  | BTR_MODIFY_EXTERNAL))
-
-#define BTR_LATCH_MODE_WITHOUT_INTENTION(latch_mode)	\
-	((latch_mode) & ~(BTR_LATCH_FOR_INSERT		\
-			  | BTR_LATCH_FOR_DELETE	\
-			  | BTR_MODIFY_EXTERNAL))
+#define BTR_RTREE_DELETE_MARK	524288U
+
+#define BTR_LATCH_MODE_WITHOUT_FLAGS(latch_mode)			\
+	((latch_mode) & btr_latch_mode(~(BTR_INSERT			\
+					 | BTR_DELETE_MARK		\
+					 | BTR_RTREE_UNDO_INS		\
+					 | BTR_RTREE_DELETE_MARK	\
+					 | BTR_DELETE			\
+					 | BTR_ESTIMATE			\
+					 | BTR_IGNORE_SEC_UNIQUE	\
+					 | BTR_ALREADY_S_LATCHED	\
+					 | BTR_LATCH_FOR_INSERT		\
+					 | BTR_LATCH_FOR_DELETE		\
+					 | BTR_MODIFY_EXTERNAL)))
+
+#define BTR_LATCH_MODE_WITHOUT_INTENTION(latch_mode)			\
+	((latch_mode) & btr_latch_mode(~(BTR_LATCH_FOR_INSERT		\
+					 | BTR_LATCH_FOR_DELETE		\
+					 | BTR_MODIFY_EXTERNAL)))
 
 /**************************************************************//**
 Report that an index page is corrupted. */
@@ -206,7 +206,7 @@ btr_block_get_func(
 	const page_size_t&	page_size,
 	ulint			mode,
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	dict_index_t*		index,
 	mtr_t*			mtr);
 
@@ -507,7 +507,7 @@ btr_insert_on_non_leaf_level_func(
 	ulint		level,	/*!< in: level, must be > 0 */
 	dtuple_t*	tuple,	/*!< in: the record to be inserted */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr);	/*!< in: mtr */
 #define btr_insert_on_non_leaf_level(f,i,l,t,m)			\
 	btr_insert_on_non_leaf_level_func(f,i,l,t,__FILE__,__LINE__,m)
diff --git a/storage/innobase/include/btr0btr.ic b/storage/innobase/include/btr0btr.ic
index 810ac8f8b67..0c4292ddcc0 100644
--- a/storage/innobase/include/btr0btr.ic
+++ b/storage/innobase/include/btr0btr.ic
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2015, 2016, MariaDB Corporation.
+Copyright (c) 2015, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -51,7 +51,7 @@ btr_block_get_func(
 	const page_size_t&	page_size,
 	ulint			mode,
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	dict_index_t*		index,
 	mtr_t*			mtr)
 {
diff --git a/storage/innobase/include/btr0cur.h b/storage/innobase/include/btr0cur.h
index 275c4dc51b0..330abd0cc17 100644
--- a/storage/innobase/include/btr0cur.h
+++ b/storage/innobase/include/btr0cur.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -142,7 +143,7 @@ btr_cur_optimistic_latch_leaves(
 	ulint*		latch_mode,
 	btr_cur_t*	cursor,
 	const char*	file,
-	ulint		line,
+	unsigned	line,
 	mtr_t*		mtr);
 
 /********************************************************************//**
@@ -185,7 +186,7 @@ btr_cur_search_to_nth_level(
 				currently has on search system:
 				RW_S_LATCH, or 0 */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr,	/*!< in/out: mini-transaction */
 	ib_uint64_t	autoinc = 0);
 				/*!< in: PAGE_ROOT_AUTO_INC to be written
@@ -205,7 +206,7 @@ btr_cur_open_at_index_side_func(
 	ulint		level,		/*!< in: level to search for
 					(0=leaf) */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr)		/*!< in/out: mini-transaction */
 	MY_ATTRIBUTE((nonnull));
 
@@ -223,7 +224,7 @@ btr_cur_open_at_rnd_pos_func(
 	ulint		latch_mode,	/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_cur_t*	cursor,		/*!< in/out: B-tree cursor */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr);		/*!< in: mtr */
 #define btr_cur_open_at_rnd_pos(i,l,c,m)				\
 	btr_cur_open_at_rnd_pos_func(i,l,c,__FILE__,__LINE__,m)
@@ -967,13 +968,13 @@ stored part. */
 significant bit of the byte at smallest address) is set to 1 if this
 field does not 'own' the externally stored field; only the owner field
 is allowed to free the field in purge! */
-#define BTR_EXTERN_OWNER_FLAG		128
+#define BTR_EXTERN_OWNER_FLAG		128U
 /** If the second most significant bit of BTR_EXTERN_LEN (i.e., the
 second most significant bit of the byte at smallest address) is 1 then
 it means that the externally stored field was inherited from an
 earlier version of the row.  In rollback we are not allowed to free an
 inherited external field. */
-#define BTR_EXTERN_INHERITED_FLAG	64
+#define BTR_EXTERN_INHERITED_FLAG	64U
 
 /** Number of searches down the B-tree in btr_cur_search_to_nth_level(). */
 extern ulint	btr_cur_n_non_sea;
diff --git a/storage/innobase/include/btr0pcur.h b/storage/innobase/include/btr0pcur.h
index 947316f0e4d..e9eedc6feb5 100644
--- a/storage/innobase/include/btr0pcur.h
+++ b/storage/innobase/include/btr0pcur.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -113,7 +114,7 @@ btr_pcur_open_low(
 	ulint		latch_mode,/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_pcur_t*	cursor, /*!< in: memory buffer for persistent cursor */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	ib_uint64_t	autoinc,/*!< in: PAGE_ROOT_AUTO_INC to be written
 				(0 if none) */
 	mtr_t*		mtr);	/*!< in: mtr */
@@ -145,7 +146,7 @@ btr_pcur_open_with_no_init_func(
 				currently has on search system:
 				RW_S_LATCH, or 0 */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr);	/*!< in: mtr */
 #define btr_pcur_open_with_no_init(ix,t,md,l,cur,has,m)			\
 	btr_pcur_open_with_no_init_func(ix,t,md,l,cur,has,__FILE__,__LINE__,m)
@@ -202,7 +203,7 @@ btr_pcur_open_on_user_rec_func(
 	btr_pcur_t*	cursor,		/*!< in: memory buffer for persistent
 					cursor */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr);		/*!< in: mtr */
 #define btr_pcur_open_on_user_rec(i,t,md,l,c,m)				\
 	btr_pcur_open_on_user_rec_func(i,t,md,l,c,__FILE__,__LINE__,m)
@@ -218,7 +219,7 @@ btr_pcur_open_at_rnd_pos_func(
 	ulint		latch_mode,	/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_pcur_t*	cursor,		/*!< in/out: B-tree pcur */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr);		/*!< in: mtr */
 #define btr_pcur_open_at_rnd_pos(i,l,c,m)				\
 	btr_pcur_open_at_rnd_pos_func(i,l,c,__FILE__,__LINE__,m)
@@ -272,7 +273,7 @@ btr_pcur_restore_position_func(
 	ulint		latch_mode,	/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_pcur_t*	cursor,		/*!< in: detached persistent cursor */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr);		/*!< in: mtr */
 #define btr_pcur_restore_position(l,cur,mtr)				\
 	btr_pcur_restore_position_func(l,cur,__FILE__,__LINE__,mtr)
diff --git a/storage/innobase/include/btr0pcur.ic b/storage/innobase/include/btr0pcur.ic
index 60790bc1316..ab3b53b65fb 100644
--- a/storage/innobase/include/btr0pcur.ic
+++ b/storage/innobase/include/btr0pcur.ic
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2015, 2016, MariaDB Corporation.
+Copyright (c) 2015, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -433,7 +433,7 @@ btr_pcur_open_low(
 	ulint		latch_mode,/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_pcur_t*	cursor, /*!< in: memory buffer for persistent cursor */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	ib_uint64_t	autoinc,/*!< in: PAGE_ROOT_AUTO_INC to be written
 				(0 if none) */
 	mtr_t*		mtr)	/*!< in: mtr */
@@ -499,7 +499,7 @@ btr_pcur_open_with_no_init_func(
 				currently has on search system:
 				RW_S_LATCH, or 0 */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr)	/*!< in: mtr */
 {
 	btr_cur_t*	btr_cursor;
@@ -574,7 +574,7 @@ btr_pcur_open_at_rnd_pos_func(
 	ulint		latch_mode,	/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_pcur_t*	cursor,		/*!< in/out: B-tree pcur */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
 	/* Initialize the cursor */
diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h
index 0279887b226..60aa6ebe45e 100644
--- a/storage/innobase/include/buf0buf.h
+++ b/storage/innobase/include/buf0buf.h
@@ -493,7 +493,7 @@ buf_page_optimistic_get(
 	buf_block_t*	block,	/*!< in: guessed block */
 	ib_uint64_t	modify_clock,/*!< in: modify clock value */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr);	/*!< in: mini-transaction */
 /********************************************************************//**
 This is used to get access to a known database page, when no waiting can be
@@ -506,7 +506,7 @@ buf_page_get_known_nowait(
 	buf_block_t*	block,	/*!< in: the known page */
 	ulint		mode,	/*!< in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr);	/*!< in: mini-transaction */
 
 /** Given a tablespace id and page number tries to get that page. If the
@@ -521,7 +521,7 @@ buf_block_t*
 buf_page_try_get_func(
 	const page_id_t&	page_id,
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	mtr_t*			mtr);
 
 /** Tries to get a page.
@@ -567,7 +567,7 @@ buf_page_get_gen(
 	buf_block_t*		guess,
 	ulint			mode,
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	mtr_t*			mtr,
 	dberr_t*		err);
 
@@ -647,7 +647,7 @@ buf_page_reset_file_page_was_freed(
 Reads the freed_page_clock of a buffer block.
 @return freed_page_clock */
 UNIV_INLINE
-ulint
+unsigned
 buf_page_get_freed_page_clock(
 /*==========================*/
 	const buf_page_t*	bpage)	/*!< in: block */
@@ -656,7 +656,7 @@ buf_page_get_freed_page_clock(
 Reads the freed_page_clock of a buffer block.
 @return freed_page_clock */
 UNIV_INLINE
-ulint
+unsigned
 buf_block_get_freed_page_clock(
 /*===========================*/
 	const buf_block_t*	block)	/*!< in: block */
@@ -720,7 +720,7 @@ buf_block_buf_fix_inc_func(
 /*=======================*/
 # ifdef UNIV_DEBUG
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line */
+	unsigned	line,	/*!< in: line */
 # endif /* UNIV_DEBUG */
 	buf_block_t*	block)	/*!< in/out: block to bufferfix */
 	MY_ATTRIBUTE((nonnull));
@@ -820,7 +820,7 @@ Gets the hash value of a block. This can be used in searches in the
 lock hash table.
 @return lock hash value */
 UNIV_INLINE
-ulint
+unsigned
 buf_block_get_lock_hash_val(
 /*========================*/
 	const buf_block_t*	block)	/*!< in: block */
@@ -1160,7 +1160,7 @@ void
 buf_page_set_old(
 /*=============*/
 	buf_page_t*	bpage,	/*!< in/out: control block */
-	ibool		old);	/*!< in: old */
+	bool		old);	/*!< in: old */
 /*********************************************************************//**
 Determine the time of first access of a block in the buffer pool.
 @return ut_time_ms() at the time of first access, 0 if not accessed */
@@ -1274,7 +1274,7 @@ buf_page_io_complete(
 Calculates the index of a buffer pool to the buf_pool[] array.
 @return the position of the buffer pool in buf_pool[] */
 UNIV_INLINE
-ulint
+unsigned
 buf_pool_index(
 /*===========*/
 	const buf_pool_t*	buf_pool)	/*!< in: buffer pool */
@@ -2204,7 +2204,7 @@ struct buf_pool_t{
 					recovery and is set to NULL
 					once the recovery is over.
 					Protected by flush_list_mutex */
-	ulint		freed_page_clock;/*!< a sequence number used
+	unsigned	freed_page_clock;/*!< a sequence number used
 					to count the number of buffer
 					blocks removed from the end of
 					the LRU list; NOTE that this
diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic
index 5e75c446bbd..66ba38cf6ab 100644
--- a/storage/innobase/include/buf0buf.ic
+++ b/storage/innobase/include/buf0buf.ic
@@ -2,7 +2,7 @@
 
 Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
-Copyright (c) 2014, 2016, MariaDB Corporation.
+Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved.
 
 Portions of this file contain modifications contributed and copyrighted by
 Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -71,12 +71,12 @@ buf_pool_get_curr_size(void)
 Calculates the index of a buffer pool to the buf_pool[] array.
 @return the position of the buffer pool in buf_pool[] */
 UNIV_INLINE
-ulint
+unsigned
 buf_pool_index(
 /*===========*/
 	const buf_pool_t*	buf_pool)	/*!< in: buffer pool */
 {
-	ulint	i = buf_pool - buf_pool_ptr;
+	unsigned	i = unsigned(buf_pool - buf_pool_ptr);
 	ut_ad(i < MAX_BUFFER_POOLS);
 	ut_ad(i < srv_buf_pool_instances);
 	return(i);
@@ -91,10 +91,8 @@ buf_pool_from_bpage(
 /*================*/
 	const buf_page_t*	bpage) /*!< in: buffer pool page */
 {
-	ulint	i;
-	i = bpage->buf_pool_index;
-	ut_ad(i < srv_buf_pool_instances);
-	return(&buf_pool_ptr[i]);
+	ut_ad(bpage->buf_pool_index < srv_buf_pool_instances);
+	return(&buf_pool_ptr[bpage->buf_pool_index]);
 }
 
 /******************************************************************//**
@@ -124,7 +122,7 @@ buf_pool_get_n_pages(void)
 Reads the freed_page_clock of a buffer block.
 @return freed_page_clock */
 UNIV_INLINE
-ulint
+unsigned
 buf_page_get_freed_page_clock(
 /*==========================*/
 	const buf_page_t*	bpage)	/*!< in: block */
@@ -137,7 +135,7 @@ buf_page_get_freed_page_clock(
 Reads the freed_page_clock of a buffer block.
 @return freed_page_clock */
 UNIV_INLINE
-ulint
+unsigned
 buf_block_get_freed_page_clock(
 /*===========================*/
 	const buf_block_t*	block)	/*!< in: block */
@@ -162,7 +160,7 @@ buf_page_peek_if_young(
 
 	/* FIXME: bpage->freed_page_clock is 31 bits */
 	return((buf_pool->freed_page_clock & ((1UL << 31) - 1))
-	       < ((ulint) bpage->freed_page_clock
+	       < (bpage->freed_page_clock
 		  + (buf_pool->curr_size
 		     * (BUF_LRU_OLD_RATIO_DIV - buf_pool->LRU_old_ratio)
 		     / (BUF_LRU_OLD_RATIO_DIV * 4))));
@@ -629,7 +627,7 @@ void
 buf_page_set_old(
 /*=============*/
 	buf_page_t*	bpage,	/*!< in/out: control block */
-	ibool		old)	/*!< in: old */
+	bool		old)	/*!< in: old */
 {
 #ifdef UNIV_DEBUG
 	buf_pool_t*	buf_pool = buf_pool_from_bpage(bpage);
@@ -792,7 +790,7 @@ Gets the hash value of the page the pointer is pointing to. This can be used
 in searches in the lock hash table.
 @return lock hash value */
 UNIV_INLINE
-ulint
+unsigned
 buf_block_get_lock_hash_val(
 /*========================*/
 	const buf_block_t*	block)	/*!< in: block */
@@ -978,7 +976,7 @@ buf_block_buf_fix_inc_func(
 /*=======================*/
 #ifdef UNIV_DEBUG
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line */
+	unsigned	line,	/*!< in: line */
 #endif /* UNIV_DEBUG */
 	buf_block_t*	block)	/*!< in/out: block to bufferfix */
 {
diff --git a/storage/innobase/include/buf0flu.h b/storage/innobase/include/buf0flu.h
index 273f9666419..f779ad65935 100644
--- a/storage/innobase/include/buf0flu.h
+++ b/storage/innobase/include/buf0flu.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2014, 2016, MariaDB Corporation
+Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -376,7 +376,7 @@ class FlushObserver {
 
 	/** Check pages have been flushed and removed from the flush list
 	in a buffer pool instance.
-	@pram[in]	instance_no	buffer pool instance no
+	@param[in]	instance_no	buffer pool instance no
 	@return true if the pages were removed from the flush list */
 	bool is_complete(ulint	instance_no)
 	{
diff --git a/storage/innobase/include/data0data.ic b/storage/innobase/include/data0data.ic
index 2fe5190591b..2f2d578c6ba 100644
--- a/storage/innobase/include/data0data.ic
+++ b/storage/innobase/include/data0data.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -221,7 +222,7 @@ dfield_write_mbr(
 #endif /* UNIV_VALGRIND_DEBUG */
 	field->ext = 0;
 
-	for (int i = 0; i < SPDIMS * 2; i++) {
+	for (unsigned i = 0; i < SPDIMS * 2; i++) {
 		mach_double_write(static_cast<byte*>(field->data)
 				  + i * sizeof(double), mbr[i]);
 	}
diff --git a/storage/innobase/include/data0type.h b/storage/innobase/include/data0type.h
index d38aa7c1533..09e85825175 100644
--- a/storage/innobase/include/data0type.h
+++ b/storage/innobase/include/data0type.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -147,7 +148,7 @@ columns, and for them the precise type is usually not used at all.
 				for InnoDB's own system tables */
 #define DATA_ERROR	111	/* another relic from pre-MySQL time */
 
-#define DATA_MYSQL_TYPE_MASK 255 /* AND with this mask to extract the MySQL
+#define DATA_MYSQL_TYPE_MASK 255U/* AND with this mask to extract the MySQL
 				 type from the precise type */
 #define DATA_MYSQL_TRUE_VARCHAR 15 /* MySQL type code for the >= 5.0.3
 				   format true VARCHAR */
@@ -168,14 +169,14 @@ be less than 256 */
 
 #define DATA_FTS_DOC_ID	3	/* Used as FTS DOC ID column */
 
-#define DATA_SYS_PRTYPE_MASK 0xF /* mask to extract the above from prtype */
+#define DATA_SYS_PRTYPE_MASK 0xFU /* mask to extract the above from prtype */
 
 /* Flags ORed to the precise data type */
-#define DATA_NOT_NULL	256	/* this is ORed to the precise type when
+#define DATA_NOT_NULL	256U	/* this is ORed to the precise type when
 				the column is declared as NOT NULL */
-#define DATA_UNSIGNED	512	/* this id ORed to the precise type when
+#define DATA_UNSIGNED	512U	/* this id ORed to the precise type when
 				we have an unsigned integer type */
-#define	DATA_BINARY_TYPE 1024	/* if the data type is a binary character
+#define	DATA_BINARY_TYPE 1024U	/* if the data type is a binary character
 				string, this is ORed to the precise type:
 				this only holds for tables created with
 				>= MySQL-4.0.14 */
@@ -183,14 +184,14 @@ be less than 256 */
 				In earlier versions this was set for some
 				BLOB columns.
 */
-#define DATA_GIS_MBR	2048	/* Used as GIS MBR column */
+#define DATA_GIS_MBR	2048U	/* Used as GIS MBR column */
 #define DATA_MBR_LEN	SPDIMS * 2 * sizeof(double) /* GIS MBR length*/
 
-#define	DATA_LONG_TRUE_VARCHAR 4096	/* this is ORed to the precise data
+#define	DATA_LONG_TRUE_VARCHAR 4096U	/* this is ORed to the precise data
 				type when the column is true VARCHAR where
 				MySQL uses 2 bytes to store the data len;
 				for shorter VARCHARs MySQL uses only 1 byte */
-#define	DATA_VIRTUAL	8192	/* Virtual column */
+#define	DATA_VIRTUAL	8192U	/* Virtual column */
 
 /** Get the number of system columns in a table. */
 #define dict_table_get_n_sys_cols(table) DATA_N_SYS_COLS
@@ -221,14 +222,12 @@ length from corresponding column or index definition, instead of this MACRO
 
 /* Pack mbminlen, mbmaxlen to mbminmaxlen. */
 #define DATA_MBMINMAXLEN(mbminlen, mbmaxlen)	\
-	((mbmaxlen) * DATA_MBMAX + (mbminlen))
-/* 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))
+	unsigned((mbmaxlen) * DATA_MBMAX + (mbminlen))
+/* Get mbminlen from mbminmaxlen. */
+#define DATA_MBMINLEN(mbminmaxlen) \
+	unsigned(UNIV_EXPECT((mbminmaxlen) % DATA_MBMAX, 1))
 /* Get mbmaxlen from mbminmaxlen. */
-#define DATA_MBMAXLEN(mbminmaxlen) ((ulint) ((mbminmaxlen) / DATA_MBMAX))
+#define DATA_MBMAXLEN(mbminmaxlen) unsigned((mbminmaxlen) / DATA_MBMAX)
 
 /* For checking if a geom_type is POINT */
 #define DATA_POINT_MTYPE(mtype) ((mtype) == DATA_POINT			\
@@ -369,16 +368,21 @@ ulint
 dtype_get_charset_coll(
 /*===================*/
 	ulint	prtype);/*!< in: precise data type */
-/*********************************************************************//**
-Forms a precise type from the < 4.1.2 format precise type plus the
+/** Form a precise type from the < 4.1.2 format precise type plus the
 charset-collation code.
+ at param[in]	old_prtype	MySQL type code and the flags
+				DATA_BINARY_TYPE etc.
+ at param[in]	charset_coll	character-set collation code
 @return precise type, including the charset-collation code */
-ulint
-dtype_form_prtype(
-/*==============*/
-	ulint	old_prtype,	/*!< in: the MySQL type code and the flags
-				DATA_BINARY_TYPE etc. */
-	ulint	charset_coll);	/*!< in: MySQL charset-collation code */
+UNIV_INLINE
+uint32_t
+dtype_form_prtype(ulint old_prtype, ulint charset_coll)
+{
+	ut_ad(old_prtype < 256 * 256);
+	ut_ad(charset_coll <= MAX_CHAR_COLL_NUM);
+	return(uint32_t(old_prtype + (charset_coll << 16)));
+}
+
 /*********************************************************************//**
 Determines if a MySQL string type is a subset of UTF-8.  This function
 may return false negatives, in case further character-set collation
diff --git a/storage/innobase/include/data0type.ic b/storage/innobase/include/data0type.ic
index 869d0ba8ed6..0b5d9735382 100644
--- a/storage/innobase/include/data0type.ic
+++ b/storage/innobase/include/data0type.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -151,9 +152,9 @@ dtype_set(
 	ut_ad(type);
 	ut_ad(mtype <= DATA_MTYPE_MAX);
 
-	type->mtype = mtype;
-	type->prtype = prtype;
-	type->len = len;
+	type->mtype = unsigned(mtype);
+	type->prtype = unsigned(prtype);
+	type->len = unsigned(len);
 
 	dtype_set_mblen(type);
 }
diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h
index 036d905f0d8..92f00549dc9 100644
--- a/storage/innobase/include/dict0dict.h
+++ b/storage/innobase/include/dict0dict.h
@@ -399,7 +399,7 @@ void
 dict_table_add_to_cache(
 /*====================*/
 	dict_table_t*	table,		/*!< in: table */
-	ibool		can_be_evicted,	/*!< in: TRUE if can be evicted*/
+	bool		can_be_evicted,	/*!< in: whether can be evicted*/
 	mem_heap_t*	heap)		/*!< in: temporary heap */
 	MY_ATTRIBUTE((nonnull));
 /**********************************************************************//**
@@ -1567,11 +1567,9 @@ dict_index_calc_min_rec_len(
 /*========================*/
 	const dict_index_t*	index)	/*!< in: index */
 	MY_ATTRIBUTE((nonnull, warn_unused_result));
-/********************************************************************//**
-Reserves the dictionary system mutex for MySQL. */
+/** Reserve the dictionary system mutex. */
 void
-dict_mutex_enter_for_mysql_func(const char * file, ulint line);
-/*============================*/
+dict_mutex_enter_for_mysql_func(const char *file, unsigned line);
 
 #define dict_mutex_enter_for_mysql() \
   dict_mutex_enter_for_mysql_func(__FILE__, __LINE__)
diff --git a/storage/innobase/include/dict0dict.ic b/storage/innobase/include/dict0dict.ic
index 905a1b78782..061153589c8 100644
--- a/storage/innobase/include/dict0dict.ic
+++ b/storage/innobase/include/dict0dict.ic
@@ -1418,7 +1418,7 @@ dict_index_set_space(
 	ut_ad(index);
 	ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
 
-	index->space = space;
+	index->space = unsigned(space);
 }
 
 /*********************************************************************//**
diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h
index a458054c225..ff28add8ca4 100644
--- a/storage/innobase/include/dict0mem.h
+++ b/storage/innobase/include/dict0mem.h
@@ -300,28 +300,28 @@ for unknown bits in order to protect backward incompatibility. */
 #define DICT_TF2_BIT_MASK		~DICT_TF2_UNUSED_BIT_MASK
 
 /** TEMPORARY; TRUE for tables from CREATE TEMPORARY TABLE. */
-#define DICT_TF2_TEMPORARY		1
+#define DICT_TF2_TEMPORARY		1U
 
 /** The table has an internal defined DOC ID column */
-#define DICT_TF2_FTS_HAS_DOC_ID		2
+#define DICT_TF2_FTS_HAS_DOC_ID		2U
 
 /** The table has an FTS index */
-#define DICT_TF2_FTS			4
+#define DICT_TF2_FTS			4U
 
 /** Need to add Doc ID column for FTS index build.
 This is a transient bit for index build */
-#define DICT_TF2_FTS_ADD_DOC_ID		8
+#define DICT_TF2_FTS_ADD_DOC_ID		8U
 
 /** This bit is used during table creation to indicate that it will
 use its own tablespace instead of the system tablespace. */
-#define DICT_TF2_USE_FILE_PER_TABLE	16
+#define DICT_TF2_USE_FILE_PER_TABLE	16U
 
 /** Set when we discard/detach the tablespace */
-#define DICT_TF2_DISCARDED		32
+#define DICT_TF2_DISCARDED		32U
 
 /** This bit is set if all aux table names (both common tables and
 index tables) of a FTS table are in HEX format. */
-#define DICT_TF2_FTS_AUX_HEX_NAME	64
+#define DICT_TF2_FTS_AUX_HEX_NAME	64U
 
 /* @} */
 
@@ -1257,12 +1257,12 @@ struct dict_foreign_set_free {
 /** The flags for ON_UPDATE and ON_DELETE can be ORed; the default is that
 a foreign key constraint is enforced, therefore RESTRICT just means no flag */
 /* @{ */
-#define DICT_FOREIGN_ON_DELETE_CASCADE	1	/*!< ON DELETE CASCADE */
-#define DICT_FOREIGN_ON_DELETE_SET_NULL	2	/*!< ON UPDATE SET NULL */
-#define DICT_FOREIGN_ON_UPDATE_CASCADE	4	/*!< ON DELETE CASCADE */
-#define DICT_FOREIGN_ON_UPDATE_SET_NULL	8	/*!< ON UPDATE SET NULL */
-#define DICT_FOREIGN_ON_DELETE_NO_ACTION 16	/*!< ON DELETE NO ACTION */
-#define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32	/*!< ON UPDATE NO ACTION */
+#define DICT_FOREIGN_ON_DELETE_CASCADE	1U	/*!< ON DELETE CASCADE */
+#define DICT_FOREIGN_ON_DELETE_SET_NULL	2U	/*!< ON UPDATE SET NULL */
+#define DICT_FOREIGN_ON_UPDATE_CASCADE	4U	/*!< ON DELETE CASCADE */
+#define DICT_FOREIGN_ON_UPDATE_SET_NULL	8U	/*!< ON UPDATE SET NULL */
+#define DICT_FOREIGN_ON_DELETE_NO_ACTION 16U	/*!< ON DELETE NO ACTION */
+#define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32U	/*!< ON UPDATE NO ACTION */
 /* @} */
 
 /** Display an identifier.
@@ -1323,7 +1323,7 @@ struct dict_vcol_templ_t {
 	/** when mysql_table was cached */
 	uint64_t		mysql_table_query_id;
 
-	dict_vcol_templ_t() : vtempl(0), mysql_table_query_id(-1) {}
+	dict_vcol_templ_t() : vtempl(0), mysql_table_query_id(~0ULL) {}
 };
 
 /** These are used when MySQL FRM and InnoDB data dictionary are
diff --git a/storage/innobase/include/dict0mem.ic b/storage/innobase/include/dict0mem.ic
index e7d68dd4b9d..92b0734a71f 100644
--- a/storage/innobase/include/dict0mem.ic
+++ b/storage/innobase/include/dict0mem.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -59,7 +60,7 @@ dict_mem_fill_index_struct(
 
 	/* Assign a ulint to a 4-bit-mapped field.
 	Only the low-order 4 bits are assigned. */
-	index->type = type;
+	index->type = unsigned(type);
 	index->space = (unsigned int) space;
 	index->page = FIL_NULL;
 	index->merge_threshold = DICT_INDEX_MERGE_THRESHOLD_DEFAULT;
diff --git a/storage/innobase/include/dict0stats.h b/storage/innobase/include/dict0stats.h
index 8941b399f7d..32c2a7a2cb3 100644
--- a/storage/innobase/include/dict0stats.h
+++ b/storage/innobase/include/dict0stats.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2009, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -77,14 +78,10 @@ dict_stats_set_persistent(
 	ibool		ps_off)	/*!< in: persistent stats explicitly disabled */
 	MY_ATTRIBUTE((nonnull));
 
-/*********************************************************************//**
-Check whether persistent statistics is enabled for a given table.
- at return TRUE if enabled, FALSE otherwise */
+/** @return whether persistent statistics is enabled for a given table */
 UNIV_INLINE
-ibool
-dict_stats_is_persistent_enabled(
-/*=============================*/
-	const dict_table_t*	table)	/*!< in: table */
+bool
+dict_stats_is_persistent_enabled(const dict_table_t* table)
 	MY_ATTRIBUTE((nonnull, warn_unused_result));
 
 /*********************************************************************//**
@@ -100,14 +97,11 @@ dict_stats_auto_recalc_set(
 	ibool		auto_recalc_on,		/*!< in: explicitly enabled */
 	ibool		auto_recalc_off);	/*!< in: explicitly disabled */
 
-/*********************************************************************//**
-Check whether auto recalc is enabled for a given table.
- at return TRUE if enabled, FALSE otherwise */
+/** @return whether auto recalc is enabled for a given table*/
 UNIV_INLINE
-ibool
-dict_stats_auto_recalc_is_enabled(
-/*==============================*/
-	const dict_table_t*	table);	/*!< in: table */
+bool
+dict_stats_auto_recalc_is_enabled(const dict_table_t* table)
+	MY_ATTRIBUTE((nonnull, warn_unused_result));
 
 /*********************************************************************//**
 Initialize table's stats for the first time when opening a table. */
diff --git a/storage/innobase/include/dict0stats.ic b/storage/innobase/include/dict0stats.ic
index 61c88773912..63ff8e8c10f 100644
--- a/storage/innobase/include/dict0stats.ic
+++ b/storage/innobase/include/dict0stats.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -60,14 +61,10 @@ dict_stats_set_persistent(
 	table->stat_persistent = stat_persistent;
 }
 
-/*********************************************************************//**
-Check whether persistent statistics is enabled for a given table.
- at return TRUE if enabled, FALSE otherwise */
+/** @return whether persistent statistics is enabled for a given table */
 UNIV_INLINE
-ibool
-dict_stats_is_persistent_enabled(
-/*=============================*/
-	const dict_table_t*	table)	/*!< in: table */
+bool
+dict_stats_is_persistent_enabled(const dict_table_t* table)
 {
 	/* Because of the nature of this check (non-locking) it is possible
 	that a table becomes:
@@ -89,9 +86,9 @@ dict_stats_is_persistent_enabled(
 
 	if (stat_persistent & DICT_STATS_PERSISTENT_ON) {
 		ut_ad(!(stat_persistent & DICT_STATS_PERSISTENT_OFF));
-		return(TRUE);
+		return(true);
 	} else if (stat_persistent & DICT_STATS_PERSISTENT_OFF) {
-		return(FALSE);
+		return(false);
 	} else {
 		return(srv_stats_persistent);
 	}
@@ -126,23 +123,19 @@ dict_stats_auto_recalc_set(
 	table->stats_auto_recalc = stats_auto_recalc;
 }
 
-/*********************************************************************//**
-Check whether auto recalc is enabled for a given table.
- at return TRUE if enabled, FALSE otherwise */
+/** @return whether auto recalc is enabled for a given table*/
 UNIV_INLINE
-ibool
-dict_stats_auto_recalc_is_enabled(
-/*==============================*/
-	const dict_table_t*	table)	/*!< in: table */
+bool
+dict_stats_auto_recalc_is_enabled(const dict_table_t* table)
 {
 	/* we rely on this read to be atomic */
 	ib_uint32_t	stats_auto_recalc = table->stats_auto_recalc;
 
 	if (stats_auto_recalc & DICT_STATS_AUTO_RECALC_ON) {
 		ut_ad(!(stats_auto_recalc & DICT_STATS_AUTO_RECALC_OFF));
-		return(TRUE);
+		return(true);
 	} else if (stats_auto_recalc & DICT_STATS_AUTO_RECALC_OFF) {
-		return(FALSE);
+		return(false);
 	} else {
 		return(srv_stats_auto_recalc);
 	}
diff --git a/storage/innobase/include/dict0types.h b/storage/innobase/include/dict0types.h
index b0623f82bb7..ad150c93a86 100644
--- a/storage/innobase/include/dict0types.h
+++ b/storage/innobase/include/dict0types.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2013, 2016, MariaDB Corporation. All Rights Reserved.
+Copyright (c) 2013, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -101,7 +101,7 @@ extern uint		ibuf_debug;
 #define SPATIAL_STATUS_SHIFT	12
 
 /** Mask to encode/decode spatial status. */
-#define SPATIAL_STATUS_MASK	(3 << SPATIAL_STATUS_SHIFT)
+#define SPATIAL_STATUS_MASK	(3U << SPATIAL_STATUS_SHIFT)
 
 #if SPATIAL_STATUS_MASK < REC_VERSION_56_MAX_INDEX_COL_LEN
 # error SPATIAL_STATUS_MASK < REC_VERSION_56_MAX_INDEX_COL_LEN
diff --git a/storage/innobase/include/fil0crypt.h b/storage/innobase/include/fil0crypt.h
index 7185857c039..7211d295c27 100644
--- a/storage/innobase/include/fil0crypt.h
+++ b/storage/innobase/include/fil0crypt.h
@@ -114,7 +114,7 @@ struct fil_space_crypt_struct : st_encryption_scheme
 	The object is expected to be placed in a buffer that
 	has been zero-initialized. */
 	fil_space_crypt_struct(
-		ulint new_type,
+		uint new_type,
 		uint new_min_key_version,
 		uint new_key_id,
 		ulint offset,
diff --git a/storage/innobase/include/fil0crypt.ic b/storage/innobase/include/fil0crypt.ic
index 65ca4def85f..fe3a21f0643 100644
--- a/storage/innobase/include/fil0crypt.ic
+++ b/storage/innobase/include/fil0crypt.ic
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 2015, 2016, MariaDB Corporation.
+Copyright (c) 2015, 2017, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -59,7 +59,7 @@ fil_page_encryption_status(
 			}
 		}
 	} else {
-		ulint key = mach_read_from_4(buf + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
+		unsigned key = mach_read_from_4(buf + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
 		if (!encryption_key_version_exists(crypt_data->key_id, key)) {
 			return 1;
 		}
diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h
index cda2fdb4656..37af9f9d156 100644
--- a/storage/innobase/include/fil0fil.h
+++ b/storage/innobase/include/fil0fil.h
@@ -176,8 +176,6 @@ struct fil_space_t {
 	/** True if page 0 of tablespace is read */
 	bool		read_page0;
 
-        /** True if we have tested if this filespace supports atomic writes */
-        bool            atomic_write_tested;
         /** True if the device this filespace is on supports atomic writes */
         bool            atomic_write_supported;
 
diff --git a/storage/innobase/include/fsp0fsp.h b/storage/innobase/include/fsp0fsp.h
index 892e6d1035e..621498b9a4c 100644
--- a/storage/innobase/include/fsp0fsp.h
+++ b/storage/innobase/include/fsp0fsp.h
@@ -862,7 +862,7 @@ fsp_page_is_free_func(
 	ulint		page,		/*!< in: page offset */
 	mtr_t*		mtr,		/*!< in/out: mini-transaction */
 	const char *file,
-	ulint line);
+	unsigned line);
 
 #define fsp_page_is_free(space,page,mtr)				\
 	fsp_page_is_free_func(space,page,mtr, __FILE__, __LINE__)
diff --git a/storage/innobase/include/fsp0types.h b/storage/innobase/include/fsp0types.h
index 429af4210b7..ec33f2e4d10 100644
--- a/storage/innobase/include/fsp0types.h
+++ b/storage/innobase/include/fsp0types.h
@@ -416,7 +416,7 @@ fsp_flags_is_valid(ulint flags)
 	bits 10..14 would be nonzero 0bsssaa where sss is
 	nonzero PAGE_SSIZE (3, 4, 6, or 7)
 	and aa is ATOMIC_WRITES (not 0b11). */
-	if (FSP_FLAGS_GET_RESERVED(flags) & ~1) {
+	if (FSP_FLAGS_GET_RESERVED(flags) & ~1U) {
 		return(false);
 	}
 
diff --git a/storage/innobase/include/gis0rtree.h b/storage/innobase/include/gis0rtree.h
index 436374fd6b2..aee66b88bca 100644
--- a/storage/innobase/include/gis0rtree.h
+++ b/storage/innobase/include/gis0rtree.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2014, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -151,7 +152,7 @@ rtr_cur_restore_position_func(
 	btr_cur_t*	cursor,		/*!< in: detached persistent cursor */
 	ulint		level,		/*!< in: index level */
 	const char*	file,		/*!< in: file name */
-	ulint		line,		/*!< in: line where called */
+	unsigned	line,		/*!< in: line where called */
 	mtr_t*		mtr);		/*!< in: mtr */
 #define rtr_cur_restore_position(l,cur,level,mtr)		\
 	rtr_cur_restore_position_func(l,cur,level,__FILE__,__LINE__,mtr)
@@ -351,7 +352,7 @@ rtr_page_get_father_node_ptr_func(
 				out: cursor on node pointer record,
 				its page x-latched */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr);	/*!< in: mtr */
 
 
@@ -402,7 +403,7 @@ rtr_pcur_open_low(
 	ulint		latch_mode,/*!< in: BTR_SEARCH_LEAF, ... */
 	btr_pcur_t*	cursor,	/*!< in: memory buffer for persistent cursor */
 	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line where called */
+	unsigned	line,	/*!< in: line where called */
 	mtr_t*		mtr);	/*!< in: mtr */
 
 #define rtr_pcur_open(i,t,md,l,c,m)			\
diff --git a/storage/innobase/include/gis0rtree.ic b/storage/innobase/include/gis0rtree.ic
index a30db122273..d1dbf146f82 100644
--- a/storage/innobase/include/gis0rtree.ic
+++ b/storage/innobase/include/gis0rtree.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -64,7 +65,7 @@ rtr_page_cal_mbr(
 
 		ut_ad(len == DATA_MBR_LEN);
 		inc = 0;
-		for (int i = 0; i < SPDIMS; i++) {
+		for (unsigned i = 0; i < SPDIMS; i++) {
 			bmin = mach_double_read(field + inc);
 			bmax = mach_double_read(field + inc + sizeof(double));
 
@@ -167,7 +168,7 @@ rtr_write_mbr(
 {
 	const double* my_mbr = reinterpret_cast<const double*>(mbr);
 
-	for (int i = 0; i < SPDIMS * 2; i++) {
+	for (unsigned i = 0; i < SPDIMS * 2; i++) {
 		mach_double_write(data + i * sizeof(double), my_mbr[i]);
 	}
 }
@@ -181,7 +182,7 @@ rtr_read_mbr(
 	const byte*	data,	/*!< in: data */
 	rtr_mbr_t*	mbr)	/*!< out: MBR */
 {
-	for (int i = 0; i < SPDIMS * 2; i++) {
+	for (unsigned i = 0; i < SPDIMS * 2; i++) {
 		(reinterpret_cast<double*>(mbr))[i] = mach_double_read(
 							data
 							+ i * sizeof(double));
diff --git a/storage/innobase/include/ibuf0ibuf.h b/storage/innobase/include/ibuf0ibuf.h
index e646f678964..7d7e2f13b8b 100644
--- a/storage/innobase/include/ibuf0ibuf.h
+++ b/storage/innobase/include/ibuf0ibuf.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2016, MariaDB Corporation.
+Copyright (c) 2016, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -274,7 +274,7 @@ ibuf_page_low(
 	ibool			x_latch,
 #endif /* UNIV_DEBUG */
 	const char*		file,
-	ulint			line,
+	unsigned		line,
 	mtr_t*			mtr)
 	MY_ATTRIBUTE((warn_unused_result));
 
diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h
index d96ba0d9c7d..b211b24d7ff 100644
--- a/storage/innobase/include/lock0lock.h
+++ b/storage/innobase/include/lock0lock.h
@@ -612,7 +612,7 @@ Calculates the hash value of a page file address: used in inserting or
 searching for a lock in the hash table.
 @return hashed value */
 UNIV_INLINE
-ulint
+unsigned
 lock_rec_hash(
 /*==========*/
 	ulint	space,	/*!< in: space */
@@ -960,15 +960,15 @@ lock_trx_alloc_locks(trx_t* trx);
 				type_mode field in a lock */
 /** Lock types */
 /* @{ */
-#define LOCK_TABLE	16	/*!< table lock */
-#define	LOCK_REC	32	/*!< record lock */
+#define LOCK_TABLE	16U	/*!< table lock */
+#define	LOCK_REC	32U	/*!< record lock */
 #define LOCK_TYPE_MASK	0xF0UL	/*!< mask used to extract lock type from the
 				type_mode field in a lock */
 #if LOCK_MODE_MASK & LOCK_TYPE_MASK
 # error "LOCK_MODE_MASK & LOCK_TYPE_MASK"
 #endif
 
-#define LOCK_WAIT	256	/*!< Waiting lock flag; when set, it
+#define LOCK_WAIT	256U	/*!< Waiting lock flag; when set, it
 				means that the lock has not yet been
 				granted, it is just waiting for its
 				turn in the wait queue */
@@ -976,14 +976,14 @@ lock_trx_alloc_locks(trx_t* trx);
 #define LOCK_ORDINARY	0	/*!< this flag denotes an ordinary
 				next-key lock in contrast to LOCK_GAP
 				or LOCK_REC_NOT_GAP */
-#define LOCK_GAP	512	/*!< when this bit is set, it means that the
+#define LOCK_GAP	512U	/*!< when this bit is set, it means that the
 				lock holds only on the gap before the record;
 				for instance, an x-lock on the gap does not
 				give permission to modify the record on which
 				the bit is set; locks of this type are created
 				when records are removed from the index chain
 				of records */
-#define LOCK_REC_NOT_GAP 1024	/*!< this bit means that the lock is only on
+#define LOCK_REC_NOT_GAP 1024U	/*!< this bit means that the lock is only on
 				the index record and does NOT block inserts
 				to the gap before the index record; this is
 				used in the case when we retrieve a record
@@ -991,7 +991,7 @@ lock_trx_alloc_locks(trx_t* trx);
 				locking plain SELECTs (not part of UPDATE
 				or DELETE) when the user has set the READ
 				COMMITTED isolation level */
-#define LOCK_INSERT_INTENTION 2048 /*!< this bit is set when we place a waiting
+#define LOCK_INSERT_INTENTION 2048U/*!< this bit is set when we place a waiting
 				gap type record lock request in order to let
 				an insert of an index record to wait until
 				there are no conflicting locks by other
@@ -999,8 +999,8 @@ lock_trx_alloc_locks(trx_t* trx);
 				remains set when the waiting lock is granted,
 				or if the lock is inherited to a neighboring
 				record */
-#define LOCK_PREDICATE	8192	/*!< Predicate lock */
-#define LOCK_PRDT_PAGE	16384	/*!< Page lock */
+#define LOCK_PREDICATE	8192U	/*!< Predicate lock */
+#define LOCK_PRDT_PAGE	16384U	/*!< Page lock */
 
 
 #if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION|LOCK_PREDICATE|LOCK_PRDT_PAGE)&LOCK_MODE_MASK
diff --git a/storage/innobase/include/lock0lock.ic b/storage/innobase/include/lock0lock.ic
index ba2311c02ea..af84ac40333 100644
--- a/storage/innobase/include/lock0lock.ic
+++ b/storage/innobase/include/lock0lock.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -56,14 +57,14 @@ Calculates the hash value of a page file address: used in inserting or
 searching for a lock in the hash table.
 @return hashed value */
 UNIV_INLINE
-ulint
+unsigned
 lock_rec_hash(
 /*==========*/
 	ulint	space,	/*!< in: space */
 	ulint	page_no)/*!< in: page number */
 {
-	return(hash_calc_hash(lock_rec_fold(space, page_no),
-			      lock_sys->rec_hash));
+	return(unsigned(hash_calc_hash(lock_rec_fold(space, page_no),
+				       lock_sys->rec_hash)));
 }
 
 /*********************************************************************//**
diff --git a/storage/innobase/include/mach0data.h b/storage/innobase/include/mach0data.h
index 3d6bccec718..df5952113a9 100644
--- a/storage/innobase/include/mach0data.h
+++ b/storage/innobase/include/mach0data.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -45,14 +46,13 @@ mach_write_to_1(
 /*============*/
 	byte*	b,	/*!< in: pointer to byte where to store */
 	ulint	n);	 /*!< in: ulint integer to be stored, >= 0, < 256 */
-/********************************************************//**
-The following function is used to fetch data from one byte.
+/** The following function is used to fetch data from one byte.
+ at param[in]	b	pointer to a byte to read
 @return ulint integer, >= 0, < 256 */
 UNIV_INLINE
-ulint
+uint8_t
 mach_read_from_1(
-/*=============*/
-	const byte*	b)	/*!< in: pointer to byte */
+	const byte*	b)
 	MY_ATTRIBUTE((warn_unused_result));
 /*******************************************************//**
 The following function is used to store data in two consecutive
@@ -63,17 +63,15 @@ mach_write_to_2(
 /*============*/
 	byte*	b,	/*!< in: pointer to two bytes where to store */
 	ulint	n);	 /*!< in: ulint integer to be stored, >= 0, < 64k */
-/********************************************************//**
-The following function is used to fetch data from two consecutive
+/** The following function is used to fetch data from 2 consecutive
 bytes. The most significant byte is at the lowest address.
- at return ulint integer, >= 0, < 64k */
+ at param[in]	b	pointer to 2 bytes where to store
+ at return 2-byte integer, >= 0, < 64k */
 UNIV_INLINE
-ulint
+uint16_t
 mach_read_from_2(
-/*=============*/
-	const byte*	b)	/*!< in: pointer to two bytes */
+	const byte*	b)
 	MY_ATTRIBUTE((warn_unused_result));
-
 /********************************************************//**
 The following function is used to convert a 16-bit data item
 to the canonical format, for fast bytewise equality test
@@ -105,15 +103,14 @@ mach_write_to_3(
 /*============*/
 	byte*	b,	/*!< in: pointer to 3 bytes where to store */
 	ulint	n);	 /*!< in: ulint integer to be stored */
-/********************************************************//**
-The following function is used to fetch data from 3 consecutive
+/** The following function is used to fetch data from 3 consecutive
 bytes. The most significant byte is at the lowest address.
- at return ulint integer */
+ at param[in]	b	pointer to 3 bytes to read
+ at return 32 bit integer */
 UNIV_INLINE
-ulint
+uint32_t
 mach_read_from_3(
-/*=============*/
-	const byte*	b)	/*!< in: pointer to 3 bytes */
+	const byte*	b)
 	MY_ATTRIBUTE((warn_unused_result));
 /*******************************************************//**
 The following function is used to store data in four consecutive
@@ -124,15 +121,14 @@ mach_write_to_4(
 /*============*/
 	byte*	b,	/*!< in: pointer to four bytes where to store */
 	ulint	n);	 /*!< in: ulint integer to be stored */
-/********************************************************//**
-The following function is used to fetch data from 4 consecutive
+/** The following function is used to fetch data from 4 consecutive
 bytes. The most significant byte is at the lowest address.
- at return ulint integer */
+ at param[in]	b	pointer to 4 bytes to read
+ at return 32 bit integer */
 UNIV_INLINE
-ulint
+uint32_t
 mach_read_from_4(
-/*=============*/
-	const byte*	b)	/*!< in: pointer to four bytes */
+	const byte*	b)
 	MY_ATTRIBUTE((warn_unused_result));
 /*********************************************************//**
 Writes a ulint in a compressed form (1..5 bytes).
diff --git a/storage/innobase/include/mach0data.ic b/storage/innobase/include/mach0data.ic
index 31cb873cdf6..77700ccb329 100644
--- a/storage/innobase/include/mach0data.ic
+++ b/storage/innobase/include/mach0data.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -62,30 +63,28 @@ mach_write_to_2(
 	b[1] = (byte)(n);
 }
 
-/********************************************************//**
-The following function is used to fetch data from one byte.
+/** The following function is used to fetch data from one byte.
+ at param[in]	b	pointer to a byte to read
 @return ulint integer, >= 0, < 256 */
 UNIV_INLINE
-ulint
+uint8_t
 mach_read_from_1(
-/*=============*/
-	const byte*	b)	/*!< in: pointer to byte */
+	const byte*	b)
 {
 	ut_ad(b);
-	return((ulint)(b[0]));
+	return(uint8_t(*b));
 }
 
-/********************************************************//**
-The following function is used to fetch data from 2 consecutive
+/** The following function is used to fetch data from 2 consecutive
 bytes. The most significant byte is at the lowest address.
- at return ulint integer */
+ at param[in]	b	pointer to 2 bytes to read
+ at return 2-byte integer, >= 0, < 64k */
 UNIV_INLINE
-ulint
+uint16_t
 mach_read_from_2(
-/*=============*/
-	const byte*	b)	/*!< in: pointer to 2 bytes */
+	const byte*	b)
 {
-	return(((ulint)(b[0]) << 8) | (ulint)(b[1]));
+	return(uint16_t(uint16_t(b[0]) << 8 | b[1]));
 }
 
 #ifndef UNIV_INNOCHECKSUM
@@ -139,23 +138,21 @@ mach_write_to_3(
 	b[2] = (byte)(n);
 }
 
-/********************************************************//**
-The following function is used to fetch data from 3 consecutive
+/** The following function is used to fetch data from 3 consecutive
 bytes. The most significant byte is at the lowest address.
- at return ulint integer */
+ at param[in]	b	pointer to 3 bytes to read
+ at return uint32_t integer */
 UNIV_INLINE
-ulint
+uint32_t
 mach_read_from_3(
-/*=============*/
-	const byte*	b)	/*!< in: pointer to 3 bytes */
+	const byte*	b)
 {
 	ut_ad(b);
-	return( ((ulint)(b[0]) << 16)
-		| ((ulint)(b[1]) << 8)
-		| (ulint)(b[2])
+	return( (static_cast<uint32_t>(b[0]) << 16)
+		| (static_cast<uint32_t>(b[1]) << 8)
+		| static_cast<uint32_t>(b[2])
 		);
 }
-
 #endif /* !UNIV_INNOCHECKSUM */
 
 /*******************************************************//**
@@ -176,21 +173,20 @@ mach_write_to_4(
 	b[3] = (byte) n;
 }
 
-/********************************************************//**
-The following function is used to fetch data from 4 consecutive
+/** The following function is used to fetch data from 4 consecutive
 bytes. The most significant byte is at the lowest address.
- at return ulint integer */
+ at param[in]	b	pointer to 4 bytes to read
+ at return 32 bit integer */
 UNIV_INLINE
-ulint
+uint32_t
 mach_read_from_4(
-/*=============*/
-	const byte*	b)	/*!< in: pointer to four bytes */
+	const byte*	b)
 {
 	ut_ad(b);
-	return( ((ulint)(b[0]) << 24)
-		| ((ulint)(b[1]) << 16)
-		| ((ulint)(b[2]) << 8)
-		| (ulint)(b[3])
+	return( (static_cast<uint32_t>(b[0]) << 24)
+		| (static_cast<uint32_t>(b[1]) << 16)
+		| (static_cast<uint32_t>(b[2]) << 8)
+		| static_cast<uint32_t>(b[3])
 		);
 }
 
diff --git a/storage/innobase/include/mem0mem.h b/storage/innobase/include/mem0mem.h
index 991d1179098..553c512765c 100644
--- a/storage/innobase/include/mem0mem.h
+++ b/storage/innobase/include/mem0mem.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -121,7 +122,7 @@ mem_heap_create_func(
 	ulint		size,
 #ifdef UNIV_DEBUG
 	const char*	file_name,
-	ulint		line,
+	unsigned	line,
 #endif /* UNIV_DEBUG */
 	ulint		type);
 
@@ -371,7 +372,7 @@ struct mem_block_info_t {
 	ulint	magic_n;/* magic number for debugging */
 #ifdef UNIV_DEBUG
 	char	file_name[8];/* file name where the mem heap was created */
-	ulint	line;	/*!< line number where the mem heap was created */
+	unsigned line;	/*!< line number where the mem heap was created */
 #endif /* UNIV_DEBUG */
 	UT_LIST_BASE_NODE_T(mem_block_t) base; /* In the first block in the
 			the list this is the base node of the list of blocks;
diff --git a/storage/innobase/include/mem0mem.ic b/storage/innobase/include/mem0mem.ic
index 82c90584e6f..b5fcf86b014 100644
--- a/storage/innobase/include/mem0mem.ic
+++ b/storage/innobase/include/mem0mem.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -48,7 +49,7 @@ mem_heap_create_block_func(
 	ulint		n,	/*!< in: number of bytes needed for user data */
 #ifdef UNIV_DEBUG
 	const char*	file_name,/*!< in: file name where created */
-	ulint		line,	/*!< in: line where created */
+	unsigned	line,	/*!< in: line where created */
 #endif /* UNIV_DEBUG */
 	ulint		type);	/*!< in: type of heap: MEM_HEAP_DYNAMIC or
 				MEM_HEAP_BUFFER */
@@ -477,7 +478,7 @@ mem_heap_create_func(
 	ulint		size,
 #ifdef UNIV_DEBUG
 	const char*	file_name,
-	ulint		line,
+	unsigned	line,
 #endif /* UNIV_DEBUG */
 	ulint		type)
 {
diff --git a/storage/innobase/include/mtr0mtr.h b/storage/innobase/include/mtr0mtr.h
index e761aaf7ec1..972209c1bf6 100644
--- a/storage/innobase/include/mtr0mtr.h
+++ b/storage/innobase/include/mtr0mtr.h
@@ -378,21 +378,21 @@ struct mtr_t {
 	@param lock	rw-lock
 	@param file	file name from where called
 	@param line	line number in file */
-	inline void s_lock(rw_lock_t* lock, const char* file, ulint line);
+	inline void s_lock(rw_lock_t* lock, const char* file, unsigned line);
 
 	/** Locks a rw-latch in X mode.
 	NOTE: use mtr_x_lock().
 	@param lock	rw-lock
 	@param file	file name from where called
 	@param line	line number in file */
-	inline void x_lock(rw_lock_t* lock, const char*	file, ulint line);
+	inline void x_lock(rw_lock_t* lock, const char*	file, unsigned line);
 
 	/** Locks a rw-latch in X mode.
 	NOTE: use mtr_sx_lock().
 	@param lock	rw-lock
 	@param file	file name from where called
 	@param line	line number in file */
-	inline void sx_lock(rw_lock_t* lock, const char* file, ulint line);
+	inline void sx_lock(rw_lock_t* lock, const char* file, unsigned line);
 
 	/** Acquire a tablespace X-latch.
 	NOTE: use mtr_x_lock_space().
@@ -403,7 +403,7 @@ struct mtr_t {
 	fil_space_t* x_lock_space(
 		ulint		space_id,
 		const char*	file,
-		ulint		line);
+		unsigned	line);
 
 	/** Release an object in the memo stack.
 	@param object	object
diff --git a/storage/innobase/include/mtr0mtr.ic b/storage/innobase/include/mtr0mtr.ic
index f0354756b23..597d036db51 100644
--- a/storage/innobase/include/mtr0mtr.ic
+++ b/storage/innobase/include/mtr0mtr.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -232,7 +233,7 @@ mtr_t::set_log_mode(mtr_log_t mode)
 Locks a lock in s-mode. */
 
 void
-mtr_t::s_lock(rw_lock_t* lock, const char* file, ulint line)
+mtr_t::s_lock(rw_lock_t* lock, const char* file, unsigned line)
 {
 	rw_lock_s_lock_inline(lock, 0, file, line);
 
@@ -243,7 +244,7 @@ mtr_t::s_lock(rw_lock_t* lock, const char* file, ulint line)
 Locks a lock in x-mode. */
 
 void
-mtr_t::x_lock(rw_lock_t* lock, const char* file, ulint line)
+mtr_t::x_lock(rw_lock_t* lock, const char* file, unsigned line)
 {
 	rw_lock_x_lock_inline(lock, 0, file, line);
 
@@ -254,7 +255,7 @@ mtr_t::x_lock(rw_lock_t* lock, const char* file, ulint line)
 Locks a lock in sx-mode. */
 
 void
-mtr_t::sx_lock(rw_lock_t* lock, const char* file, ulint line)
+mtr_t::sx_lock(rw_lock_t* lock, const char* file, unsigned line)
 {
 	rw_lock_sx_lock_inline(lock, 0, file, line);
 
diff --git a/storage/innobase/include/os0file.h b/storage/innobase/include/os0file.h
index ffe7b1a48bf..e30c427dff6 100644
--- a/storage/innobase/include/os0file.h
+++ b/storage/innobase/include/os0file.h
@@ -110,7 +110,7 @@ whole block gets written. This should be true even in most cases of a crash:
 if this fails for a log block, then it is equivalent to a media failure in the
 log. */
 
-#define OS_FILE_LOG_BLOCK_SIZE		512
+#define OS_FILE_LOG_BLOCK_SIZE		512U
 
 /** Options for os_file_create_func @{ */
 enum os_file_create_t {
@@ -861,7 +861,7 @@ pfs_os_file_create_simple_func(
 	bool		read_only,
 	bool*		success,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 	MY_ATTRIBUTE((warn_unused_result));
 
 /** NOTE! Please use the corresponding macro
@@ -892,7 +892,7 @@ pfs_os_file_create_simple_no_error_handling_func(
 	bool		read_only,
 	bool*		success,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 	MY_ATTRIBUTE((warn_unused_result));
 
 /** NOTE! Please use the corresponding macro os_file_create(), not directly
@@ -926,7 +926,7 @@ pfs_os_file_create_func(
 	bool		read_only,
 	bool*		success,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 	MY_ATTRIBUTE((warn_unused_result));
 
 /** NOTE! Please use the corresponding macro os_file_close(), not directly
@@ -941,7 +941,7 @@ bool
 pfs_os_file_close_func(
 	os_file_t	file,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 /** NOTE! Please use the corresponding macro os_file_read(), not directly
 this function!
@@ -964,7 +964,7 @@ pfs_os_file_read_func(
 	os_offset_t	offset,
 	ulint		n,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 /** NOTE! Please use the corresponding macro os_file_read_no_error_handling(),
 not directly this function!
@@ -990,7 +990,7 @@ pfs_os_file_read_no_error_handling_func(
 	ulint		n,
 	ulint*		o,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 /** NOTE! Please use the corresponding macro os_aio(), not directly this
 function!
@@ -1028,7 +1028,7 @@ pfs_os_aio_func(
 	fil_node_t*	m1,
 	void*		m2,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 /** NOTE! Please use the corresponding macro os_file_write(), not directly
 this function!
@@ -1054,7 +1054,7 @@ pfs_os_file_write_func(
 	os_offset_t	offset,
 	ulint		n,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 /** NOTE! Please use the corresponding macro os_file_flush(), not directly
 this function!
@@ -1070,7 +1070,7 @@ bool
 pfs_os_file_flush_func(
 	os_file_t	file,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 /** NOTE! Please use the corresponding macro os_file_rename(), not directly
 this function!
@@ -1089,7 +1089,7 @@ pfs_os_file_rename_func(
 	const char*	oldpath,
 	const char*	newpath,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 /**
 NOTE! Please use the corresponding macro os_file_delete(), not directly
@@ -1107,7 +1107,7 @@ pfs_os_file_delete_func(
 	mysql_pfs_key_t	key,
 	const char*	name,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 /**
 NOTE! Please use the corresponding macro os_file_delete_if_exists(), not
@@ -1127,7 +1127,7 @@ pfs_os_file_delete_if_exists_func(
 	const char*	name,
 	bool*		exist,
 	const char*	src_file,
-	ulint		src_line);
+	uint		src_line);
 
 #else /* UNIV_PFS_IO */
 
diff --git a/storage/innobase/include/os0file.ic b/storage/innobase/include/os0file.ic
index 5c7c4d45ca6..807d3254b9d 100644
--- a/storage/innobase/include/os0file.ic
+++ b/storage/innobase/include/os0file.ic
@@ -52,7 +52,7 @@ pfs_os_file_create_simple_func(
 	bool		read_only,
 	bool*		success,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker* locker = NULL;
@@ -101,7 +101,7 @@ pfs_os_file_create_simple_no_error_handling_func(
 	bool		read_only,
 	bool*		success,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker* locker = NULL;
@@ -152,7 +152,7 @@ pfs_os_file_create_func(
 	bool		read_only,
 	bool*		success,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker* locker = NULL;
@@ -184,7 +184,7 @@ bool
 pfs_os_file_close_func(
 	os_file_t	file,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker*	locker = NULL;
@@ -236,7 +236,7 @@ pfs_os_aio_func(
 	fil_node_t*	m1,
 	void*		m2,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker*	locker = NULL;
@@ -278,7 +278,7 @@ pfs_os_file_read_func(
 	os_offset_t	offset,
 	ulint		n,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker*	locker = NULL;
@@ -321,7 +321,7 @@ pfs_os_file_read_no_error_handling_func(
 	ulint		n,
 	ulint*		o,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker*	locker = NULL;
@@ -361,7 +361,7 @@ pfs_os_file_write_func(
 	os_offset_t	offset,
 	ulint		n,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker*	locker = NULL;
@@ -392,7 +392,7 @@ bool
 pfs_os_file_flush_func(
 	os_file_t	file,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker*	locker = NULL;
@@ -424,7 +424,7 @@ pfs_os_file_rename_func(
 	const char*	oldpath,
 	const char*	newpath,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 
 {
 	PSI_file_locker_state	state;
@@ -456,7 +456,7 @@ pfs_os_file_delete_func(
 	mysql_pfs_key_t	key,
 	const char*	name,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker*	locker = NULL;
@@ -489,7 +489,7 @@ pfs_os_file_delete_if_exists_func(
 	const char*	name,
 	bool*		exist,
 	const char*	src_file,
-	ulint		src_line)
+	uint		src_line)
 {
 	PSI_file_locker_state	state;
 	struct PSI_file_locker*	locker = NULL;
@@ -504,4 +504,3 @@ pfs_os_file_delete_if_exists_func(
 	return(result);
 }
 #endif /* UNIV_PFS_IO */
-
diff --git a/storage/innobase/include/page0page.ic b/storage/innobase/include/page0page.ic
index a70ca3da8d8..3940931125e 100644
--- a/storage/innobase/include/page0page.ic
+++ b/storage/innobase/include/page0page.ic
@@ -252,7 +252,7 @@ page_header_set_ptr(
 	if (ptr == NULL) {
 		offs = 0;
 	} else {
-		offs = ptr - page;
+		offs = ulint(ptr - page);
 	}
 
 	ut_ad((field != PAGE_HEAP_TOP) || offs);
@@ -1248,11 +1248,9 @@ page_mem_free(
 	ut_ad(rec_offs_validate(rec, index, offsets));
 	free = page_header_get_ptr(page, PAGE_FREE);
 
-	bool scrub = srv_immediate_scrub_data_uncompressed;
-	if (scrub) {
+	if (srv_immediate_scrub_data_uncompressed) {
 		/* scrub record */
-		uint size = rec_offs_data_size(offsets);
-		memset(rec, 0, size);
+		memset(rec, 0, rec_offs_data_size(offsets));
 	}
 
 	page_rec_set_next(rec, free);
diff --git a/storage/innobase/include/page0size.h b/storage/innobase/include/page0size.h
index ca173db9b6d..30a996df0a6 100644
--- a/storage/innobase/include/page0size.h
+++ b/storage/innobase/include/page0size.h
@@ -82,7 +82,7 @@ class page_size_t {
 		ssize = (0 == ssize) ? UNIV_PAGE_SSIZE_ORIG : ssize;
 
 		/* Convert from a 'log2 minus 9' to a page size in bytes. */
-		const ulint	size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
+		const unsigned	size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
 
 		ut_ad(size <= UNIV_PAGE_SIZE_MAX);
 		ut_ad(size <= (1 << PAGE_SIZE_T_SIZE_BITS));
@@ -102,7 +102,7 @@ class page_size_t {
 
 			/* Convert from a 'log2 minus 9' to a page size
 			in bytes. */
-			const ulint	phy
+			const unsigned	phy
 				= ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
 
 			ut_ad(phy <= UNIV_ZIP_SIZE_MAX);
diff --git a/storage/innobase/include/page0zip.h b/storage/innobase/include/page0zip.h
index 4a32595af66..98dbb32ebd8 100644
--- a/storage/innobase/include/page0zip.h
+++ b/storage/innobase/include/page0zip.h
@@ -2,6 +2,7 @@
 
 Copyright (c) 2005, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2012, Facebook Inc.
+Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -69,11 +70,11 @@ extern uint	page_zip_level;
 		+ DATA_TRX_ID_LEN		\
 		+ DATA_ROLL_PTR_LEN)
 /** Mask of record offsets */
-#define PAGE_ZIP_DIR_SLOT_MASK		0x3fff
+#define PAGE_ZIP_DIR_SLOT_MASK		0x3fffU
 /** 'owned' flag */
-#define PAGE_ZIP_DIR_SLOT_OWNED		0x4000
+#define PAGE_ZIP_DIR_SLOT_OWNED		0x4000U
 /** 'deleted' flag */
-#define PAGE_ZIP_DIR_SLOT_DEL		0x8000
+#define PAGE_ZIP_DIR_SLOT_DEL		0x8000U
 
 /* Whether or not to log compressed page images to avoid possible
 compression algorithm changes in zlib. */
diff --git a/storage/innobase/include/page0zip.ic b/storage/innobase/include/page0zip.ic
index 9cc54dc42fa..921c2d4db28 100644
--- a/storage/innobase/include/page0zip.ic
+++ b/storage/innobase/include/page0zip.ic
@@ -2,6 +2,7 @@
 
 Copyright (c) 2005, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2012, Facebook Inc.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -133,11 +134,11 @@ page_zip_set_size(
 	ulint		size)		/*!< in: size in bytes */
 {
 	if (size) {
-		int	ssize;
+		unsigned	ssize;
 
 		ut_ad(ut_is_2pow(size));
 
-		for (ssize = 1; size > (ulint) (512 << ssize); ssize++) {
+		for (ssize = 1; size > (512U << ssize); ssize++) {
 		}
 
 		page_zip->ssize = ssize;
@@ -268,9 +269,9 @@ page_zip_max_ins_size(
 
 	trailer_len += PAGE_ZIP_DIR_SLOT_SIZE;
 
-	return((lint) page_zip_get_size(page_zip)
-	       - trailer_len - page_zip->m_end
-	       - (REC_N_NEW_EXTRA_BYTES - 2));
+	return(lint(page_zip_get_size(page_zip)
+		    - trailer_len - page_zip->m_end
+		    - (REC_N_NEW_EXTRA_BYTES - 2)));
 }
 
 /**********************************************************************//**
diff --git a/storage/innobase/include/rem0rec.h b/storage/innobase/include/rem0rec.h
index ed700139b53..5bc6a8f5198 100644
--- a/storage/innobase/include/rem0rec.h
+++ b/storage/innobase/include/rem0rec.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -458,7 +459,7 @@ rec_get_offsets_func(
 					 (ULINT_UNDEFINED if all fields) */
 #ifdef UNIV_DEBUG
 	const char*		file,	/*!< in: file name where called */
-	ulint			line,	/*!< in: line number where called */
+	unsigned		line,	/*!< in: line number where called */
 #endif /* UNIV_DEBUG */
 	mem_heap_t**		heap)	/*!< in/out: memory heap */
 #ifdef UNIV_DEBUG
diff --git a/storage/innobase/include/row0ins.h b/storage/innobase/include/row0ins.h
index 4038c32b9c0..94404e2c520 100644
--- a/storage/innobase/include/row0ins.h
+++ b/storage/innobase/include/row0ins.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -153,7 +154,7 @@ row_ins_index_entry_big_rec_func(
 #ifndef DBUG_OFF
 	const void*		thd,	/*!< in: connection, or NULL */
 #endif /* DBUG_OFF */
-	ulint			line)	/*!< in: line number of caller */
+	unsigned		line)	/*!< in: line number of caller */
 	MY_ATTRIBUTE((nonnull(1,2,3,4,5,6), warn_unused_result));
 #ifdef DBUG_OFF
 # define row_ins_index_entry_big_rec(e,big,ofs,heap,index,thd,file,line) \
diff --git a/storage/innobase/include/row0merge.h b/storage/innobase/include/row0merge.h
index 9e71ee42bb0..20efde03db0 100644
--- a/storage/innobase/include/row0merge.h
+++ b/storage/innobase/include/row0merge.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2005, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2015, 2016, MariaDB Corporation.
+Copyright (c) 2015, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -283,8 +283,8 @@ row_merge_create_index(
 
 /*********************************************************************//**
 Check if a transaction can use an index.
- at return TRUE if index can be used by the transaction else FALSE */
-ibool
+ at return whether the index can be used by the transaction */
+bool
 row_merge_is_index_usable(
 /*======================*/
 	const trx_t*		trx,	/*!< in: transaction */
diff --git a/storage/innobase/include/row0mysql.h b/storage/innobase/include/row0mysql.h
index 607f7c96389..a84f9efd5a5 100644
--- a/storage/innobase/include/row0mysql.h
+++ b/storage/innobase/include/row0mysql.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -337,7 +338,7 @@ row_mysql_lock_data_dictionary_func(
 /*================================*/
 	trx_t*		trx,	/*!< in/out: transaction */
 	const char*	file,	/*!< in: file name */
-	ulint		line);	/*!< in: line number */
+	unsigned	line);	/*!< in: line number */
 #define row_mysql_lock_data_dictionary(trx)				\
 	row_mysql_lock_data_dictionary_func(trx, __FILE__, __LINE__)
 /*********************************************************************//**
@@ -354,7 +355,7 @@ row_mysql_freeze_data_dictionary_func(
 /*==================================*/
 	trx_t*		trx,	/*!< in/out: transaction */
 	const char*	file,	/*!< in: file name */
-	ulint		line);	/*!< in: line number */
+	unsigned	line);	/*!< in: line number */
 #define row_mysql_freeze_data_dictionary(trx)				\
 	row_mysql_freeze_data_dictionary_func(trx, __FILE__, __LINE__)
 /*********************************************************************//**
diff --git a/storage/innobase/include/row0upd.ic b/storage/innobase/include/row0upd.ic
index 8b794e47a07..1e59f616b2e 100644
--- a/storage/innobase/include/row0upd.ic
+++ b/storage/innobase/include/row0upd.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -97,10 +98,10 @@ upd_field_set_field_no(
 	dict_index_t*	index,		/*!< in: index */
 	trx_t*		trx)		/*!< in: transaction */
 {
-	upd_field->field_no = field_no;
+	upd_field->field_no = unsigned(field_no);
 	upd_field->orig_len = 0;
 
-	if (field_no >= dict_index_get_n_fields(index)) {
+	if (UNIV_UNLIKELY(field_no >= dict_index_get_n_fields(index))) {
 		ib::error()
 			<< " trying to access field " << field_no
 			<< " in " << index->name
@@ -125,19 +126,10 @@ upd_field_set_v_field_no(
 	ulint		field_no,
 	dict_index_t*	index)
 {
-	upd_field->field_no = field_no;
+	ut_a(field_no < dict_table_get_n_v_cols(index->table));
+	upd_field->field_no = unsigned(field_no);
 	upd_field->orig_len = 0;
 
-	if (field_no >= dict_table_get_n_v_cols(index->table)) {
-		ib::error()
-			<< " trying to access virtual field " << field_no
-			<< " in " << index->name
-			<< " of table " << index->table->name
-			<< " which contains only " << index->table->n_v_cols
-			<< " virutal columns";
-		ut_ad(0);
-	}
-
 	dict_col_copy_type(&dict_table_get_nth_v_col(
 				index->table, field_no)->m_col,
 			   dfield_get_type(&upd_field->new_val));
diff --git a/storage/innobase/include/sync0arr.h b/storage/innobase/include/sync0arr.h
index bc419a9be8f..034ace53447 100644
--- a/storage/innobase/include/sync0arr.h
+++ b/storage/innobase/include/sync0arr.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2015, 2016, MariaDB Corporation.
+Copyright (c) 2015, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -49,7 +49,7 @@ sync_array_get_and_reserve_cell(
 	void*		object,	/*!< in: pointer to the object to wait for */
 	ulint		type,	/*!< in: lock request type */
 	const char*	file,	/*!< in: file where requested */
-	ulint		line,	/*!< in: line where requested */
+	unsigned	line,	/*!< in: line where requested */
 	sync_cell_t**	cell);	/*!< out: the cell reserved, never NULL */
 /******************************************************************//**
 Reserves a wait array cell for waiting for an object.
@@ -60,7 +60,7 @@ sync_array_reserve_cell(
 	void*		object, /*!< in: pointer to the object to wait for */
 	ulint		type,	/*!< in: lock request type */
 	const char*	file,	/*!< in: file where requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 
 /******************************************************************//**
 This function should be called when a thread starts to wait on
diff --git a/storage/innobase/include/sync0arr.ic b/storage/innobase/include/sync0arr.ic
index a15e2176278..dd376e799b9 100644
--- a/storage/innobase/include/sync0arr.ic
+++ b/storage/innobase/include/sync0arr.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -61,7 +62,7 @@ sync_array_get_and_reserve_cell(
 	void*		object, /*!< in: pointer to the object to wait for */
 	ulint		type,	/*!< in: lock request type */
 	const char*	file,	/*!< in: file where requested */
-	ulint		line,	/*!< in: line where requested */
+	unsigned	line,	/*!< in: line where requested */
 	sync_cell_t**	cell)	/*!< out: the cell reserved, never NULL */
 {
 	sync_array_t*	sync_arr = NULL;
diff --git a/storage/innobase/include/sync0policy.h b/storage/innobase/include/sync0policy.h
index 0eaefc7167a..2e05f92d0d3 100644
--- a/storage/innobase/include/sync0policy.h
+++ b/storage/innobase/include/sync0policy.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2013, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -70,7 +71,7 @@ class MutexDebug {
 		void locked(
 			const Mutex*		mutex,
 			const char*		filename,
-			ulint			line)
+			unsigned		line)
 			UNIV_NOTHROW
 		{
 			m_mutex = mutex;
@@ -92,7 +93,7 @@ class MutexDebug {
 
 			m_filename = NULL;
 
-			m_line = ULINT_UNDEFINED;
+			m_line = 0;
 		}
 
 		/** Print information about the latch
@@ -134,7 +135,7 @@ class MutexDebug {
 		const char*	m_filename;
 
 		/** Line mumber in filename */
-		ulint		m_line;
+		unsigned	m_line;
 
 		/** Thread ID of the thread that own(ed) the mutex */
 		os_thread_id_t	m_thread_id;
@@ -176,7 +177,7 @@ class MutexDebug {
 	void enter(
 		const Mutex*	mutex,
 		const char*	filename,
-		ulint		line)
+		unsigned	line)
 		UNIV_NOTHROW;
 
 	/** Called when the mutex is locked
@@ -186,7 +187,7 @@ class MutexDebug {
 	void locked(
 		const Mutex*	mutex,
 		const char*	filename,
-		ulint		line)
+		unsigned	line)
 		UNIV_NOTHROW;
 
 	/** Called when the mutex is released
@@ -210,7 +211,7 @@ class MutexDebug {
 	}
 
 	/** @return the name of the file from the mutex was acquired */
-	ulint get_enter_line() const
+	unsigned get_enter_line() const
 		UNIV_NOTHROW
 	{
 		return(m_context.m_line);
@@ -240,7 +241,7 @@ struct NoPolicy {
 	void init(const Mutex&, latch_id_t, const char*, uint32_t)
 		UNIV_NOTHROW { }
 	void destroy() UNIV_NOTHROW { }
-	void enter(const Mutex&, const char*, ulint line) UNIV_NOTHROW { }
+	void enter(const Mutex&, const char*, unsigned line) UNIV_NOTHROW { }
 	void add(uint32_t, uint32_t) UNIV_NOTHROW { }
 	void locked(const Mutex&, const char*, ulint) UNIV_NOTHROW { }
 	void release(const Mutex&) UNIV_NOTHROW { }
@@ -293,7 +294,7 @@ struct GenericPolicy
 
 		meta.get_counter()->single_register(&m_count);
 
-		sync_file_created_register(this, filename, line);
+		sync_file_created_register(this, filename, uint16_t(line));
 
 		ut_d(MutexDebug<MutexType>::init(m_id));
 	}
@@ -341,7 +342,7 @@ struct GenericPolicy
 	void enter(
 		const MutexType&	mutex,
 		const char*		filename,
-		ulint			line)
+		unsigned		line)
 		UNIV_NOTHROW
 	{
 		ut_d(MutexDebug<MutexType>::enter(&mutex, filename, line));
@@ -354,7 +355,7 @@ struct GenericPolicy
 	void locked(
 		const MutexType&	mutex,
 		const char*		filename,
-		ulint			line)
+		unsigned		line)
 		UNIV_NOTHROW
 	{
 		ut_d(MutexDebug<MutexType>::locked(&mutex, filename, line));
@@ -492,7 +493,7 @@ class BlockMutexPolicy
 	void locked(
 		const MutexType&	mutex,
 		const char*		filename,
-		ulint			line)
+		unsigned		line)
 		UNIV_NOTHROW
 	{
 		ut_d(MutexDebug<MutexType>::locked(&mutex, filename, line));
@@ -513,7 +514,7 @@ class BlockMutexPolicy
 	void enter(
 		const MutexType&	mutex,
 		const char*		filename,
-		ulint			line)
+		unsigned		line)
 		UNIV_NOTHROW
 	{
 		ut_d(MutexDebug<MutexType>::enter(&mutex, filename, line));
diff --git a/storage/innobase/include/sync0policy.ic b/storage/innobase/include/sync0policy.ic
index f7598fe7854..b38c5b13979 100644
--- a/storage/innobase/include/sync0policy.ic
+++ b/storage/innobase/include/sync0policy.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2013, 2015, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -57,7 +58,7 @@ template <typename Mutex>
 void MutexDebug<Mutex>::enter(
 	const Mutex*	mutex,
 	const char*	name,
-	ulint		line)
+	unsigned	line)
 	UNIV_NOTHROW
 {
 	ut_ad(!is_owned());
@@ -75,7 +76,7 @@ template <typename Mutex>
 void MutexDebug<Mutex>::locked(
 	const Mutex*	mutex,
 	const char*	name,
-	ulint		line)
+	unsigned	line)
 	UNIV_NOTHROW
 {
 	ut_ad(!is_owned());
diff --git a/storage/innobase/include/sync0rw.h b/storage/innobase/include/sync0rw.h
index 79532790f76..cf4a646cdcc 100644
--- a/storage/innobase/include/sync0rw.h
+++ b/storage/innobase/include/sync0rw.h
@@ -302,7 +302,7 @@ rw_lock_create_func(
 	latch_level_t	level,		/*!< in: level */
 #endif /* UNIV_DEBUG */
 	const char*	cfile_name,	/*!< in: file name where created */
-	ulint		cline);		/*!< in: file line where created */
+	unsigned	cline);		/*!< in: file line where created */
 /******************************************************************//**
 Calling this function is obligatory only if the memory buffer containing
 the rw-lock is freed. Removes an rw-lock object from the global list. The
@@ -334,7 +334,7 @@ rw_lock_s_lock_low(
 				/*!< in: pass value; != 0, if the lock will be
 				passed to another thread to unlock */
 	const char*	file_name, /*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 NOTE! Use the corresponding macro, not directly this function, except if
 you supply the file name and line number. Lock an rw-lock in shared mode
@@ -350,7 +350,7 @@ rw_lock_s_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 NOTE! Use the corresponding macro, not directly this function! Lock an
 rw-lock in exclusive mode for the current thread if the lock can be
@@ -362,7 +362,7 @@ rw_lock_x_lock_func_nowait(
 /*=======================*/
 	rw_lock_t*	lock,	/*!< in: pointer to rw-lock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Releases a shared mode lock. */
 UNIV_INLINE
@@ -391,7 +391,7 @@ rw_lock_x_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Low-level function for acquiring an sx lock.
 @return FALSE if did not succeed, TRUE if success. */
@@ -402,7 +402,7 @@ rw_lock_sx_lock_low(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 NOTE! Use the corresponding macro, not directly this function! Lock an
 rw-lock in SX mode for the current thread. If the rw-lock is locked
@@ -419,7 +419,7 @@ rw_lock_sx_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Releases an exclusive mode lock. */
 UNIV_INLINE
@@ -688,7 +688,7 @@ struct	rw_lock_debug_t {
 	ulint	lock_type;	/*!< Type of the lock: RW_LOCK_X,
 				RW_LOCK_S, RW_LOCK_X_WAIT */
 	const char*	file_name;/*!< File name where the lock was obtained */
-	ulint	line;		/*!< Line where the rw-lock was locked */
+	unsigned	line;	/*!< Line where the rw-lock was locked */
 	UT_LIST_NODE_T(rw_lock_debug_t) list;
 				/*!< Debug structs are linked in a two-way
 				list */
@@ -737,7 +737,7 @@ pfs_rw_lock_create_func(
 	latch_level_t	level,		/*!< in: level */
 #endif /* UNIV_DEBUG */
 	const char*	cfile_name,	/*!< in: file name where created */
-	ulint		cline);		/*!< in: file line where created */
+	unsigned	cline);		/*!< in: file line where created */
 
 /******************************************************************//**
 Performance schema instrumented wrap function for rw_lock_x_lock_func()
@@ -751,7 +751,7 @@ pfs_rw_lock_x_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Performance schema instrumented wrap function for
 rw_lock_x_lock_func_nowait()
@@ -763,7 +763,7 @@ pfs_rw_lock_x_lock_func_nowait(
 /*===========================*/
 	rw_lock_t*	lock,	/*!< in: pointer to rw-lock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Performance schema instrumented wrap function for rw_lock_s_lock_func()
 NOTE! Please use the corresponding macro rw_lock_s_lock(), not directly
@@ -776,7 +776,7 @@ pfs_rw_lock_s_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Performance schema instrumented wrap function for rw_lock_s_lock_func()
 NOTE! Please use the corresponding macro rw_lock_s_lock(), not directly
@@ -791,7 +791,7 @@ pfs_rw_lock_s_lock_low(
 				lock will be passed to another
 				thread to unlock */
 	const char*	file_name, /*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Performance schema instrumented wrap function for rw_lock_x_lock_func()
 NOTE! Please use the corresponding macro rw_lock_x_lock(), not directly
@@ -804,7 +804,7 @@ pfs_rw_lock_x_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Performance schema instrumented wrap function for rw_lock_s_unlock_func()
 NOTE! Please use the corresponding macro rw_lock_s_unlock(), not directly
@@ -845,7 +845,7 @@ pfs_rw_lock_sx_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Performance schema instrumented wrap function for rw_lock_sx_lock_nowait()
 NOTE! Please use the corresponding macro, not directly
@@ -858,7 +858,7 @@ pfs_rw_lock_sx_lock_low(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 /******************************************************************//**
 Performance schema instrumented wrap function for rw_lock_sx_unlock_func()
 NOTE! Please use the corresponding macro rw_lock_sx_unlock(), not directly
diff --git a/storage/innobase/include/sync0rw.ic b/storage/innobase/include/sync0rw.ic
index 0d2c28d9d19..21872cc8bee 100644
--- a/storage/innobase/include/sync0rw.ic
+++ b/storage/innobase/include/sync0rw.ic
@@ -45,7 +45,7 @@ rw_lock_s_lock_spin(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line);	/*!< in: line where requested */
+	unsigned	line);	/*!< in: line where requested */
 #ifdef UNIV_DEBUG
 /******************************************************************//**
 Inserts the debug information for an rw-lock. */
@@ -56,7 +56,7 @@ rw_lock_add_debug_info(
 	ulint		pass,		/*!< in: pass value */
 	ulint		lock_type,	/*!< in: lock type */
 	const char*	file_name,	/*!< in: file where requested */
-	ulint		line);		/*!< in: line where requested */
+	unsigned	line);		/*!< in: line where requested */
 /******************************************************************//**
 Removes a debug information struct for an rw-lock. */
 void
@@ -237,7 +237,7 @@ rw_lock_s_lock_low(
 				/*!< in: pass value; != 0, if the lock will be
 				passed to another thread to unlock */
 	const char*	file_name, /*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	if (!rw_lock_lock_word_decr(lock, 1, 0)) {
 		/* Locking did not succeed */
@@ -268,7 +268,7 @@ rw_lock_s_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	/* NOTE: As we do not know the thread ids for threads which have
 	s-locked a latch, and s-lockers will be served only after waiting
@@ -303,7 +303,7 @@ rw_lock_x_lock_func_nowait(
 /*=======================*/
 	rw_lock_t*	lock,	/*!< in: pointer to rw-lock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	lint oldval = X_LOCK_DECR;
 
@@ -493,7 +493,7 @@ pfs_rw_lock_create_func(
 	latch_level_t	level,		/*!< in: level */
 # endif /* UNIV_DEBUG */
 	const char*	cfile_name,	/*!< in: file name where created */
-	ulint		cline)		/*!< in: file line where created */
+	unsigned	cline)		/*!< in: file line where created */
 {
 	ut_d(new(lock) rw_lock_t());
 
@@ -520,7 +520,7 @@ pfs_rw_lock_x_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	if (lock->pfs_psi != NULL) {
 		PSI_rwlock_locker*	locker;
@@ -558,7 +558,7 @@ pfs_rw_lock_x_lock_func_nowait(
 	rw_lock_t*	lock,	/*!< in: pointer to rw-lock */
 	const char*	file_name,/*!< in: file name where lock
 				requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	ibool		ret;
 
@@ -617,7 +617,7 @@ pfs_rw_lock_s_lock_func(
 				thread to unlock */
 	const char*	file_name,/*!< in: file name where lock
 				requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	if (lock->pfs_psi != NULL) {
 		PSI_rwlock_locker*	locker;
@@ -652,7 +652,7 @@ pfs_rw_lock_sx_lock_func(
 				thread to unlock */
 	const char*	file_name,/*!< in: file name where lock
 				requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	if (lock->pfs_psi != NULL) {
 		PSI_rwlock_locker*	locker;
@@ -687,7 +687,7 @@ pfs_rw_lock_s_lock_low(
 				lock will be passed to another
 				thread to unlock */
 	const char*	file_name, /*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	ibool		ret;
 
@@ -727,7 +727,7 @@ pfs_rw_lock_sx_lock_low(
 				lock will be passed to another
 				thread to unlock */
 	const char*	file_name, /*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	ibool		ret;
 
diff --git a/storage/innobase/include/trx0rec.h b/storage/innobase/include/trx0rec.h
index 90f4604043b..0f2e5d9c411 100644
--- a/storage/innobase/include/trx0rec.h
+++ b/storage/innobase/include/trx0rec.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -353,16 +354,16 @@ record */
 					fields of the record can change */
 #define	TRX_UNDO_DEL_MARK_REC	14	/* delete marking of a record; fields
 					do not change */
-#define	TRX_UNDO_CMPL_INFO_MULT	16	/* compilation info is multiplied by
+#define	TRX_UNDO_CMPL_INFO_MULT	16U	/* compilation info is multiplied by
 					this and ORed to the type above */
-#define	TRX_UNDO_UPD_EXTERN	128	/* This bit can be ORed to type_cmpl
+#define	TRX_UNDO_UPD_EXTERN	128U	/* This bit can be ORed to type_cmpl
 					to denote that we updated external
 					storage fields: used by purge to
 					free the external storage */
 
 /* Operation type flags used in trx_undo_report_row_operation */
-#define	TRX_UNDO_INSERT_OP		1
-#define	TRX_UNDO_MODIFY_OP		2
+#define	TRX_UNDO_INSERT_OP		1U
+#define	TRX_UNDO_MODIFY_OP		2U
 
 #ifndef UNIV_NONINL
 #include "trx0rec.ic"
diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h
index 062cac2b9ab..708fd484a9b 100644
--- a/storage/innobase/include/trx0trx.h
+++ b/storage/innobase/include/trx0trx.h
@@ -1242,7 +1242,7 @@ struct trx_t {
 					read-write. */
 	/*------------------------------*/
 #ifdef UNIV_DEBUG
-	ulint		start_line;	/*!< Track where it was started from */
+	unsigned	start_line;	/*!< Track where it was started from */
 	const char*	start_file;	/*!< Filename where it was started */
 #endif /* UNIV_DEBUG */
 
@@ -1347,8 +1347,8 @@ trx_is_started(
 
 /* Treatment of duplicate values (trx->duplicates; for example, in inserts).
 Multiple flags can be combined with bitwise OR. */
-#define TRX_DUP_IGNORE	1	/* duplicate rows are to be updated */
-#define TRX_DUP_REPLACE	2	/* duplicate rows are to be replaced */
+#define TRX_DUP_IGNORE	1U	/* duplicate rows are to be updated */
+#define TRX_DUP_REPLACE	2U	/* duplicate rows are to be replaced */
 
 
 /** Commit node states */
diff --git a/storage/innobase/include/trx0types.h b/storage/innobase/include/trx0types.h
index 37a53f900eb..9109d9142ca 100644
--- a/storage/innobase/include/trx0types.h
+++ b/storage/innobase/include/trx0types.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -62,7 +63,7 @@ is set.  */
 static const ib_uint32_t TRX_FORCE_ROLLBACK_ASYNC = 1 << 30;
 
 /** Mark the transaction for forced rollback */
-static const ib_uint32_t TRX_FORCE_ROLLBACK = 1 << 31;
+static const ib_uint32_t TRX_FORCE_ROLLBACK = 1U << 31;
 
 /** For masking out the above four flags */
 static const ib_uint32_t TRX_FORCE_ROLLBACK_MASK = 0x1FFFFFFF;
diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i
index 908fb60e956..edb018c46e2 100644
--- a/storage/innobase/include/univ.i
+++ b/storage/innobase/include/univ.i
@@ -302,7 +302,7 @@ definitions: */
 
 /** The following alignment is used in memory allocations in memory heap
 management to ensure correct alignment for doubles etc. */
-#define UNIV_MEM_ALIGNMENT	8
+#define UNIV_MEM_ALIGNMENT	8U
 
 /*
 			DATABASE VERSION CONTROL
@@ -400,19 +400,19 @@ and 2 bits for flags. This limits the uncompressed page size to 16k.
 #define UNIV_PAGE_SSIZE_ORIG		(UNIV_PAGE_SIZE_SHIFT_ORIG - 9)
 
 /** Minimum page size InnoDB currently supports. */
-#define UNIV_PAGE_SIZE_MIN	(1 << UNIV_PAGE_SIZE_SHIFT_MIN)
+#define UNIV_PAGE_SIZE_MIN	(1U << UNIV_PAGE_SIZE_SHIFT_MIN)
 /** Maximum page size InnoDB currently supports. */
-#define UNIV_PAGE_SIZE_MAX	(1 << UNIV_PAGE_SIZE_SHIFT_MAX)
+#define UNIV_PAGE_SIZE_MAX	(1U << UNIV_PAGE_SIZE_SHIFT_MAX)
 /** Default page size for InnoDB tablespaces. */
-#define UNIV_PAGE_SIZE_DEF	(1 << UNIV_PAGE_SIZE_SHIFT_DEF)
+#define UNIV_PAGE_SIZE_DEF	(1U << UNIV_PAGE_SIZE_SHIFT_DEF)
 /** Original 16k page size for InnoDB tablespaces. */
-#define UNIV_PAGE_SIZE_ORIG	(1 << UNIV_PAGE_SIZE_SHIFT_ORIG)
+#define UNIV_PAGE_SIZE_ORIG	(1U << UNIV_PAGE_SIZE_SHIFT_ORIG)
 
 /** Smallest compressed page size */
-#define UNIV_ZIP_SIZE_MIN	(1 << UNIV_ZIP_SIZE_SHIFT_MIN)
+#define UNIV_ZIP_SIZE_MIN	(1U << UNIV_ZIP_SIZE_SHIFT_MIN)
 
 /** Largest compressed page size */
-#define UNIV_ZIP_SIZE_MAX	(1 << UNIV_ZIP_SIZE_SHIFT_MAX)
+#define UNIV_ZIP_SIZE_MAX	(1U << UNIV_ZIP_SIZE_SHIFT_MAX)
 
 /** Largest possible ssize for an uncompressed page.
 (The convention 'ssize' is used for 'log2 minus 9' or the number of
@@ -584,7 +584,7 @@ contains the sum of the following flag and the locally stored len. */
 /* Tell the compiler that 'expr' probably evaluates to 'constant'. */
 # define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)
 /* Tell the compiler that a pointer is likely to be NULL */
-# define UNIV_LIKELY_NULL(ptr) __builtin_expect((ulint) ptr, 0)
+# define UNIV_LIKELY_NULL(ptr) __builtin_expect((ptr) != 0, 0)
 /* Minimize cache-miss latency by moving data at addr into a cache before
 it is read. */
 # define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3)
diff --git a/storage/innobase/include/ut0dbg.h b/storage/innobase/include/ut0dbg.h
index 1a61ed84a38..48e13481cab 100644
--- a/storage/innobase/include/ut0dbg.h
+++ b/storage/innobase/include/ut0dbg.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -43,7 +44,7 @@ ut_dbg_assertion_failed(
 /*====================*/
 	const char*	expr,	/*!< in: the failed assertion */
 	const char*	file,	/*!< in: source file containing the assertion */
-	ulint		line)	/*!< in: line number of the assertion */
+	unsigned	line)	/*!< in: line number of the assertion */
 	UNIV_COLD MY_ATTRIBUTE((nonnull(2), noreturn));
 
 /** Abort execution if EXPR does not evaluate to nonzero.
@@ -51,13 +52,13 @@ ut_dbg_assertion_failed(
 #define ut_a(EXPR) do {						\
 	if (UNIV_UNLIKELY(!(ulint) (EXPR))) {			\
 		ut_dbg_assertion_failed(#EXPR,			\
-				__FILE__, (ulint) __LINE__);	\
+				__FILE__, __LINE__);		\
 	}							\
 } while (0)
 
 /** Abort execution. */
 #define ut_error						\
-	ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__)
+	ut_dbg_assertion_failed(0, __FILE__, __LINE__)
 
 #ifdef UNIV_DEBUG
 /** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
diff --git a/storage/innobase/include/ut0mem.ic b/storage/innobase/include/ut0mem.ic
index 224ff98b0f4..8d9637743d9 100644
--- a/storage/innobase/include/ut0mem.ic
+++ b/storage/innobase/include/ut0mem.ic
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -118,15 +119,15 @@ ut_raw_to_hex(
 
 #define MK_UINT16(a, b) (((uint16) (a)) << 8 | (uint16) (b))
 
-#define UINT16_GET_A(u)	((unsigned char) ((u) >> 8))
-#define UINT16_GET_B(u)	((unsigned char) ((u) & 0xFF))
+#define UINT16_GET_A(u)	((char) ((u) >> 8))
+#define UINT16_GET_B(u)	((char) ((u) & 0xFF))
 
 #else /* WORDS_BIGENDIAN */
 
 #define MK_UINT16(a, b) (((uint16) (b)) << 8 | (uint16) (a))
 
-#define UINT16_GET_A(u)	((unsigned char) ((u) & 0xFF))
-#define UINT16_GET_B(u)	((unsigned char) ((u) >> 8))
+#define UINT16_GET_A(u)	((char) ((u) & 0xFF))
+#define UINT16_GET_B(u)	((char) ((u) >> 8))
 
 #endif /* WORDS_BIGENDIAN */
 
diff --git a/storage/innobase/include/ut0mutex.h b/storage/innobase/include/ut0mutex.h
index 354fd9e0a7a..bd3603ad4d0 100644
--- a/storage/innobase/include/ut0mutex.h
+++ b/storage/innobase/include/ut0mutex.h
@@ -78,19 +78,22 @@ typedef BlockSyncArrayMutex ib_bpmutex_t;
 extern uint	srv_spin_wait_delay;
 extern ulong	srv_n_spin_wait_rounds;
 
-#define mutex_create(I, M)		mutex_init((M), (I), __FILE__, __LINE__)
+#define mutex_create(I, M)		mutex_init((M), (I),		\
+						   __FILE__, __LINE__)
 
-#define mutex_enter(M)			(M)->enter(			\
-					srv_n_spin_wait_rounds,		\
-					srv_spin_wait_delay,		\
-					__FILE__, __LINE__)
+#define mutex_enter_loc(M,file,line)	(M)->enter(			\
+					uint32_t(srv_n_spin_wait_rounds), \
+					uint32_t(srv_spin_wait_delay),	\
+					file, line)
+#define mutex_enter(M)			mutex_enter_loc(M, __FILE__, __LINE__)
 
 #define mutex_enter_nospin(M)		(M)->enter(			\
 					0,				\
 					0,				\
-					__FILE__, __LINE__)
+					__FILE__, uint32_t(__LINE__))
 
-#define mutex_enter_nowait(M)		(M)->trylock(__FILE__, __LINE__)
+#define mutex_enter_nowait(M)		(M)->trylock(__FILE__,		\
+						     uint32_t(__LINE__))
 
 #define mutex_exit(M)			(M)->exit()
 
diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc
index 3916bf9961f..a8ce60ca328 100644
--- a/storage/innobase/lock/lock0lock.cc
+++ b/storage/innobase/lock/lock0lock.cc
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2014, 2016, MariaDB Corporation
+Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -1109,7 +1109,7 @@ lock_rec_reset_nth_bit(
 	ut_ad(i < lock->un_member.rec_lock.n_bits);
 
 	byte*	b = reinterpret_cast<byte*>(&lock[1]) + (i >> 3);
-	byte	mask = 1 << (i & 7);
+	byte	mask = static_cast<byte>(1U << (i & 7));
 	byte	bit = *b & mask;
 	*b &= ~mask;
 
@@ -1717,7 +1717,7 @@ RecLock::lock_alloc(
 
 	/* Setup the lock attributes */
 
-	lock->type_mode = LOCK_REC | (mode & ~LOCK_TYPE_MASK);
+	lock->type_mode = uint32_t(LOCK_REC | (mode & ~LOCK_TYPE_MASK));
 
 	lock_rec_t&	rec_lock = lock->un_member.rec_lock;
 
diff --git a/storage/innobase/mem/mem0mem.cc b/storage/innobase/mem/mem0mem.cc
index ff793821895..9acf0b528e4 100644
--- a/storage/innobase/mem/mem0mem.cc
+++ b/storage/innobase/mem/mem0mem.cc
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -272,7 +273,7 @@ mem_heap_create_block_func(
 	ulint		n,	/*!< in: number of bytes needed for user data */
 #ifdef UNIV_DEBUG
 	const char*	file_name,/*!< in: file name where created */
-	ulint		line,	/*!< in: line where created */
+	unsigned	line,	/*!< in: line where created */
 #endif /* UNIV_DEBUG */
 	ulint		type)	/*!< in: type of heap: MEM_HEAP_DYNAMIC or
 				MEM_HEAP_BUFFER */
diff --git a/storage/innobase/mtr/mtr0log.cc b/storage/innobase/mtr/mtr0log.cc
index a63ad40a3b0..783fdcd05ac 100644
--- a/storage/innobase/mtr/mtr0log.cc
+++ b/storage/innobase/mtr/mtr0log.cc
@@ -101,7 +101,7 @@ mlog_parse_initial_log_record(
 		return(NULL);
 	}
 
-	*type = (mlog_id_t)((ulint)*ptr & ~MLOG_SINGLE_REC_FLAG);
+	*type = mlog_id_t(*ptr & ~MLOG_SINGLE_REC_FLAG);
 	ut_ad(*type <= MLOG_BIGGEST_TYPE || EXTRA_CHECK_MLOG_NUMBER(*type));
 
 	ptr++;
diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc
index 418cd7042c6..c19d2131d1e 100644
--- a/storage/innobase/mtr/mtr0mtr.cc
+++ b/storage/innobase/mtr/mtr0mtr.cc
@@ -124,11 +124,11 @@ struct FindPage
 		/* There must be some flags to look for. */
 		ut_ad(flags);
 		/* We can only look for page-related flags. */
-		ut_ad(!(flags & ~(MTR_MEMO_PAGE_S_FIX
-				  | MTR_MEMO_PAGE_X_FIX
-				  | MTR_MEMO_PAGE_SX_FIX
-				  | MTR_MEMO_BUF_FIX
-				  | MTR_MEMO_MODIFY)));
+		ut_ad(!(flags & ulint(~(MTR_MEMO_PAGE_S_FIX
+					| MTR_MEMO_PAGE_X_FIX
+					| MTR_MEMO_PAGE_SX_FIX
+					| MTR_MEMO_BUF_FIX
+					| MTR_MEMO_MODIFY))));
 	}
 
 	/** Visit a memo entry.
@@ -680,7 +680,7 @@ NOTE: use mtr_x_lock_space().
 @param[in]	line		line number in file
 @return the tablespace object (never NULL) */
 fil_space_t*
-mtr_t::x_lock_space(ulint space_id, const char* file, ulint line)
+mtr_t::x_lock_space(ulint space_id, const char* file, unsigned line)
 {
 	fil_space_t*	space;
 
@@ -1053,14 +1053,14 @@ struct FlaggedCheck {
 		/* There must be some flags to look for. */
 		ut_ad(flags);
 		/* Look for rw-lock-related and page-related flags. */
-		ut_ad(!(flags & ~(MTR_MEMO_PAGE_S_FIX
-				  | MTR_MEMO_PAGE_X_FIX
-				  | MTR_MEMO_PAGE_SX_FIX
-				  | MTR_MEMO_BUF_FIX
-				  | MTR_MEMO_MODIFY
-				  | MTR_MEMO_X_LOCK
-				  | MTR_MEMO_SX_LOCK
-				  | MTR_MEMO_S_LOCK)));
+		ut_ad(!(flags & ulint(~(MTR_MEMO_PAGE_S_FIX
+					| MTR_MEMO_PAGE_X_FIX
+					| MTR_MEMO_PAGE_SX_FIX
+					| MTR_MEMO_BUF_FIX
+					| MTR_MEMO_MODIFY
+					| MTR_MEMO_X_LOCK
+					| MTR_MEMO_SX_LOCK
+					| MTR_MEMO_S_LOCK))));
 		/* Either some rw-lock-related or page-related flags
 		must be specified, but not both at the same time. */
 		ut_ad(!(flags & (MTR_MEMO_PAGE_S_FIX
diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc
index e4bc2754b40..f71602c43b9 100644
--- a/storage/innobase/os/os0file.cc
+++ b/storage/innobase/os/os0file.cc
@@ -366,7 +366,7 @@ class AIO {
 	void print(FILE* file);
 
 	/** @return the number of slots per segment */
-	ulint slots_per_segment() const
+	unsigned slots_per_segment() const
 		MY_ATTRIBUTE((warn_unused_result))
 	{
 		return(m_slots.size() / m_n_segments);
@@ -437,7 +437,7 @@ class AIO {
 	@param[in]	max_events	number of events
 	@param[out]	io_ctx		io_ctx to initialize.
 	@return true on success. */
-	static bool linux_create_io_ctx(ulint max_events, io_context_t* io_ctx)
+	static bool linux_create_io_ctx(unsigned max_events, io_context_t* io_ctx)
 		MY_ATTRIBUTE((warn_unused_result));
 
 	/** Checks if the system supports native linux aio. On some kernel
@@ -2129,7 +2129,7 @@ AIO::linux_dispatch(Slot* slot)
 @return true on success. */
 bool
 AIO::linux_create_io_ctx(
-	ulint		max_events,
+	unsigned	max_events,
 	io_context_t*	io_ctx)
 {
 	ssize_t		n_retries = 0;
@@ -2907,8 +2907,8 @@ os_file_create_func(
 	on_error_silent = create_mode & OS_FILE_ON_ERROR_SILENT
 		? true : false;
 
-	create_mode &= ~OS_FILE_ON_ERROR_NO_EXIT;
-	create_mode &= ~OS_FILE_ON_ERROR_SILENT;
+	create_mode &= ulint(~(OS_FILE_ON_ERROR_NO_EXIT
+			       | OS_FILE_ON_ERROR_SILENT));
 
 	if (create_mode == OS_FILE_OPEN
 	    || create_mode == OS_FILE_OPEN_RAW
@@ -5759,7 +5759,7 @@ AIO::init_linux_native_aio()
 	}
 
 	io_context**	ctx = m_aio_ctx;
-	ulint		max_events = slots_per_segment();
+	unsigned	max_events = slots_per_segment();
 
 	for (ulint i = 0; i < m_n_segments; ++i, ++ctx) {
 
diff --git a/storage/innobase/page/page0page.cc b/storage/innobase/page/page0page.cc
index e2d2dd40fd8..369b3947c85 100644
--- a/storage/innobase/page/page0page.cc
+++ b/storage/innobase/page/page0page.cc
@@ -2,6 +2,7 @@
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2012, Facebook Inc.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -1162,8 +1163,7 @@ page_delete_rec_list_end(
 
 			if (scrub) {
 				/* scrub record */
-				uint recsize = rec_offs_data_size(offsets);
-				memset(rec2, 0, recsize);
+				memset(rec2, 0, rec_offs_data_size(offsets));
 			}
 
 			rec2 = page_rec_get_next(rec2);
diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc
index d49cecdb968..00b819ebfd9 100644
--- a/storage/innobase/page/page0zip.cc
+++ b/storage/innobase/page/page0zip.cc
@@ -2,6 +2,7 @@
 
 Copyright (c) 2005, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2012, Facebook Inc.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -1595,9 +1596,9 @@ page_zip_compress(
 #ifdef UNIV_DEBUG
 	page_zip->m_start =
 #endif /* UNIV_DEBUG */
-		page_zip->m_end = PAGE_DATA + c_stream.total_out;
+		page_zip->m_end = unsigned(PAGE_DATA + c_stream.total_out);
 	page_zip->m_nonempty = FALSE;
-	page_zip->n_blobs = n_blobs;
+	page_zip->n_blobs = unsigned(n_blobs);
 	/* Copy those header fields that will not be written
 	in buf_flush_init_for_writing() */
 	memcpy(page_zip->data + FIL_PAGE_PREV, page + FIL_PAGE_PREV,
@@ -1714,7 +1715,7 @@ page_zip_fields_decode(
 	index = dict_mem_index_create("ZIP_DUMMY", "ZIP_DUMMY",
 				      DICT_HDR_SPACE, 0, n);
 	index->table = table;
-	index->n_uniq = n;
+	index->n_uniq = unsigned(n);
 	/* avoid ut_ad(index->cached) in dict_index_get_n_unique_in_tree */
 	index->cached = TRUE;
 
@@ -1773,7 +1774,7 @@ page_zip_fields_decode(
 			page_zip_fields_free(index);
 			index = NULL;
 		} else {
-			index->n_nullable = val;
+			index->n_nullable = unsigned(val);
 		}
 	}
 
@@ -2429,7 +2430,7 @@ page_zip_decompress_node_ptrs(
 	}
 
 #ifdef UNIV_DEBUG
-	page_zip->m_start = PAGE_DATA + d_stream->total_in;
+	page_zip->m_start = unsigned(PAGE_DATA + d_stream->total_in);
 #endif /* UNIV_DEBUG */
 
 	/* Apply the modification log. */
@@ -2444,7 +2445,7 @@ page_zip_decompress_node_ptrs(
 		if (UNIV_UNLIKELY(!mod_log_ptr)) {
 			return(FALSE);
 		}
-		page_zip->m_end = mod_log_ptr - page_zip->data;
+		page_zip->m_end = unsigned(mod_log_ptr - page_zip->data);
 		page_zip->m_nonempty = mod_log_ptr != d_stream->next_in;
 	}
 
@@ -2582,9 +2583,7 @@ page_zip_decompress_sec(
 		       - d_stream->next_out);
 	}
 
-#ifdef UNIV_DEBUG
-	page_zip->m_start = PAGE_DATA + d_stream->total_in;
-#endif /* UNIV_DEBUG */
+	ut_d(page_zip->m_start = unsigned(PAGE_DATA + d_stream->total_in));
 
 	/* Apply the modification log. */
 	{
@@ -2598,7 +2597,7 @@ page_zip_decompress_sec(
 		if (UNIV_UNLIKELY(!mod_log_ptr)) {
 			return(FALSE);
 		}
-		page_zip->m_end = mod_log_ptr - page_zip->data;
+		page_zip->m_end = unsigned(mod_log_ptr - page_zip->data);
 		page_zip->m_nonempty = mod_log_ptr != d_stream->next_in;
 	}
 
@@ -2913,9 +2912,7 @@ page_zip_decompress_clust(
 		       - d_stream->next_out);
 	}
 
-#ifdef UNIV_DEBUG
-	page_zip->m_start = PAGE_DATA + d_stream->total_in;
-#endif /* UNIV_DEBUG */
+	ut_d(page_zip->m_start = unsigned(PAGE_DATA + d_stream->total_in));
 
 	/* Apply the modification log. */
 	{
@@ -2929,7 +2926,7 @@ page_zip_decompress_clust(
 		if (UNIV_UNLIKELY(!mod_log_ptr)) {
 			return(FALSE);
 		}
-		page_zip->m_end = mod_log_ptr - page_zip->data;
+		page_zip->m_end = unsigned(mod_log_ptr - page_zip->data);
 		page_zip->m_nonempty = mod_log_ptr != d_stream->next_in;
 	}
 
@@ -3132,7 +3129,7 @@ page_zip_decompress_low(
 	d_stream.avail_in = static_cast<uInt>(
 		page_zip_get_size(page_zip) - (PAGE_DATA + 1));
 	d_stream.next_out = page + PAGE_ZIP_START;
-	d_stream.avail_out = UNIV_PAGE_SIZE - PAGE_ZIP_START;
+	d_stream.avail_out = uInt(UNIV_PAGE_SIZE - PAGE_ZIP_START);
 
 	if (UNIV_UNLIKELY(inflateInit2(&d_stream, UNIV_PAGE_SIZE_SHIFT)
 			  != Z_OK)) {
@@ -3853,7 +3850,7 @@ page_zip_write_rec(
 
 	ut_a(!*data);
 	ut_ad((ulint) (data - page_zip->data) < page_zip_get_size(page_zip));
-	page_zip->m_end = data - page_zip->data;
+	page_zip->m_end = unsigned(data - page_zip->data);
 	page_zip->m_nonempty = TRUE;
 
 #ifdef UNIV_ZIP_DEBUG
@@ -4919,7 +4916,7 @@ page_zip_calc_checksum(
 	srv_checksum_algorithm_t	algo,
 	bool				use_legacy_big_endian /* = false */)
 {
-	uint32_t	adler;
+	uLong		adler;
 	const Bytef*	s = static_cast<const byte*>(data);
 
 	/* Exclude FIL_PAGE_SPACE_OR_CHKSUM, FIL_PAGE_LSN,
@@ -4959,7 +4956,7 @@ page_zip_calc_checksum(
 			static_cast<uInt>(size)
 			- FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
 
-		return(adler);
+		return(uint32_t(adler));
 	case SRV_CHECKSUM_ALGORITHM_NONE:
 	case SRV_CHECKSUM_ALGORITHM_STRICT_NONE:
 		return(BUF_NO_CHECKSUM_MAGIC);
diff --git a/storage/innobase/rem/rem0rec.cc b/storage/innobase/rem/rem0rec.cc
index 920fdb62079..c5881ecf447 100644
--- a/storage/innobase/rem/rem0rec.cc
+++ b/storage/innobase/rem/rem0rec.cc
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -549,7 +550,7 @@ rec_get_offsets_func(
 					 (ULINT_UNDEFINED if all fields) */
 #ifdef UNIV_DEBUG
 	const char*		file,	/*!< in: file name where called */
-	ulint			line,	/*!< in: line number where called */
+	unsigned		line,	/*!< in: line number where called */
 #endif /* UNIV_DEBUG */
 	mem_heap_t**		heap)	/*!< in/out: memory heap */
 {
diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc
index 1f884017dd3..25edb18df1a 100644
--- a/storage/innobase/row/row0ins.cc
+++ b/storage/innobase/row/row0ins.cc
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2016, MariaDB Corporation.
+Copyright (c) 2016, 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -2836,7 +2836,7 @@ row_ins_sec_index_entry_low(
 			rtr_info_update_btr(&cursor, &rtr_info);
 			mtr_start(&mtr);
 			mtr.set_named_space(index->space);
-			search_mode &= ~BTR_MODIFY_LEAF;
+			search_mode &= ulint(~BTR_MODIFY_LEAF);
 			search_mode |= BTR_MODIFY_TREE;
 			err = btr_cur_search_to_nth_level(
 				index, 0, entry, PAGE_CUR_RTREE_INSERT,
@@ -3086,7 +3086,7 @@ row_ins_index_entry_big_rec_func(
 #ifndef DBUG_OFF
 	const void*		thd,    /*!< in: connection, or NULL */
 #endif /* DBUG_OFF */
-	ulint			line)	/*!< in: line number of caller */
+	unsigned		line)	/*!< in: line number of caller */
 {
 	mtr_t		mtr;
 	btr_pcur_t	pcur;
diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc
index 8fc7ecf75ac..ef832c38b95 100644
--- a/storage/innobase/row/row0merge.cc
+++ b/storage/innobase/row/row0merge.cc
@@ -4511,7 +4511,7 @@ row_merge_create_index(
 
 /*********************************************************************//**
 Check if a transaction can use an index. */
-ibool
+bool
 row_merge_is_index_usable(
 /*======================*/
 	const trx_t*		trx,	/*!< in: transaction */
@@ -4520,7 +4520,7 @@ row_merge_is_index_usable(
 	if (!dict_index_is_clust(index)
 	    && dict_index_is_online_ddl(index)) {
 		/* Indexes that are being created are not useable. */
-		return(FALSE);
+		return(false);
 	}
 
 	return(!dict_index_is_corrupted(index)
diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc
index fbf49d8d3a0..ab5736f88d7 100644
--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -2344,7 +2344,7 @@ row_mysql_freeze_data_dictionary_func(
 /*==================================*/
 	trx_t*		trx,	/*!< in/out: transaction */
 	const char*	file,	/*!< in: file name */
-	ulint		line)	/*!< in: line number */
+	unsigned	line)	/*!< in: line number */
 {
 	ut_a(trx->dict_operation_lock_mode == 0);
 
@@ -2377,7 +2377,7 @@ row_mysql_lock_data_dictionary_func(
 /*================================*/
 	trx_t*		trx,	/*!< in/out: transaction */
 	const char*	file,	/*!< in: file name */
-	ulint		line)	/*!< in: line number */
+	unsigned	line)	/*!< in: line number */
 {
 	ut_a(trx->dict_operation_lock_mode == 0
 	     || trx->dict_operation_lock_mode == RW_X_LATCH);
diff --git a/storage/innobase/row/row0trunc.cc b/storage/innobase/row/row0trunc.cc
index b8002b439da..2402b4807ba 100644
--- a/storage/innobase/row/row0trunc.cc
+++ b/storage/innobase/row/row0trunc.cc
@@ -1558,7 +1558,7 @@ row_truncate_update_system_tables(
 			fts_update_next_doc_id(trx, table, NULL, 0);
 			fts_cache_clear(table->fts->cache);
 			fts_cache_init(table->fts->cache);
-			table->fts->fts_status &= ~TABLE_DICT_LOCKED;
+			table->fts->fts_status &= uint(~TABLE_DICT_LOCKED);
 		}
 	}
 
diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc
index 65991a711a3..46d3a7aff0e 100644
--- a/storage/innobase/srv/srv0start.cc
+++ b/storage/innobase/srv/srv0start.cc
@@ -1319,7 +1319,7 @@ srv_init_abort_low(
 	bool		create_new_db,
 #ifdef UNIV_DEBUG
 	const char*	file,
-	ulint		line,
+	unsigned	line,
 #endif /* UNIV_DEBUG */
 	dberr_t		err)
 {
diff --git a/storage/innobase/sync/sync0arr.cc b/storage/innobase/sync/sync0arr.cc
index c9423a04fba..1e2e744ceaa 100644
--- a/storage/innobase/sync/sync0arr.cc
+++ b/storage/innobase/sync/sync0arr.cc
@@ -2,7 +2,7 @@
 
 Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
-Copyright (c) 2013, 2015, MariaDB Corporation. All Rights Reserved.
+Copyright (c) 2013, 2017, MariaDB Corporation. All Rights Reserved.
 
 Portions of this file contain modifications contributed and copyrighted by
 Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -117,7 +117,7 @@ struct sync_cell_t {
 	const char*	file;		/*!< in debug version file where
 					requested */
 	ulint		line;		/*!< in debug version line where
-					requested */
+					requested, or ULINT_UNDEFINED */
 	os_thread_id_t	thread_id;	/*!< thread id of this waiting
 					thread */
 	bool		waiting;	/*!< TRUE if the thread has already
@@ -213,24 +213,16 @@ sync_array_t::sync_array_t(ulint num_cells)
 	UNIV_NOTHROW
 	:
 	n_reserved(),
-	n_cells(),
-	array(),
+	n_cells(num_cells),
+	array(UT_NEW_ARRAY_NOKEY(sync_cell_t, num_cells)),
 	mutex(),
 	res_count(),
 	next_free_slot(),
-	first_free_slot()
+	first_free_slot(ULINT_UNDEFINED)
 {
 	ut_a(num_cells > 0);
 
-	array = UT_NEW_ARRAY_NOKEY(sync_cell_t, num_cells);
-
-	ulint	sz = sizeof(sync_cell_t) * num_cells;
-
-	memset(array, 0x0, sz);
-
-	n_cells = num_cells;
-
-	first_free_slot = ULINT_UNDEFINED;
+	memset(array, 0x0, sizeof(sync_cell_t) * n_cells);
 
 	/* Then create the mutex to protect the wait array */
 	mutex_create(LATCH_ID_SYNC_ARRAY_MUTEX, &mutex);
@@ -344,7 +336,7 @@ sync_array_reserve_cell(
 	void*		object, /*!< in: pointer to the object to wait for */
 	ulint		type,	/*!< in: lock request type */
 	const char*	file,	/*!< in: file where requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	sync_cell_t*	cell;
 
@@ -604,15 +596,15 @@ sync_array_cell_print(
 			fprintf(file,
 				"number of readers %lu, waiters flag %lu,"
 				" lock_word: %lx\n"
-				"Last time read locked in file %s line %lu\n"
-				"Last time write locked in file %s line %lu\n",
+				"Last time read locked in file %s line %u\n"
+				"Last time write locked in file %s line %u\n",
 				(ulint) rw_lock_get_reader_count(rwlock),
 				(ulint) rwlock->waiters,
 				rwlock->lock_word,
 				innobase_basename(rwlock->last_s_file_name),
-				(ulint) rwlock->last_s_line,
+				rwlock->last_s_line,
 				rwlock->last_x_file_name,
-				(ulint) rwlock->last_x_line);
+				rwlock->last_x_line);
 
 			/* JAN: TODO: FIX LATER
 			fprintf(file,
@@ -1339,7 +1331,8 @@ sync_arr_fill_sys_semphore_waits_table(
 			(longlong)os_thread_pf(cell->thread)));
 			*/
 			OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_FILE], innobase_basename(cell->file)));
-			OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LINE], cell->line));
+			OK(fields[SYS_SEMAPHORE_WAITS_LINE]->store(cell->line, true));
+			fields[SYS_SEMAPHORE_WAITS_LINE]->set_notnull();
 			OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_WAIT_TIME], (ulint)difftime(time(NULL), cell->reservation_time)));
 
 			if (type == SYNC_MUTEX) {
@@ -1352,13 +1345,16 @@ sync_arr_fill_sys_semphore_waits_table(
 					OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_WAIT_TYPE], "MUTEX"));
 					//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_HOLDER_THREAD_ID], (longlong)mutex->thread_id));
 					//OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_HOLDER_FILE], innobase_basename(mutex->file_name)));
-					//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE], mutex->line));
+					//OK(fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->store(mutex->line, true));
+					//fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->set_notnull();
 					//OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_CREATED_FILE], innobase_basename(mutex->cfile_name)));
-					//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_CREATED_LINE], mutex->cline));
+					//OK(fields[SYS_SEMAPHORE_WAITS_CREATED_LINE]->store(mutex->cline, true));
+					//fields[SYS_SEMAPHORE_WAITS_CREATED_LINE]->set_notnull();
 					//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_WAITERS_FLAG], (longlong)mutex->waiters));
 					//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LOCK_WORD], (longlong)mutex->lock_word));
 					//OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_FILE], innobase_basename(mutex->file_name)));
-					//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_LINE], mutex->line));
+					//OK(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_LINE]->store(mutex->line, true));
+					//fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_LINE]->set_notnull();
 					//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_OS_WAIT_COUNT], mutex->count_os_wait));
 				}
 			} else if (type == RW_LOCK_X_WAIT
@@ -1398,14 +1394,17 @@ sync_arr_fill_sys_semphore_waits_table(
 
 						//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_HOLDER_THREAD_ID], (longlong)rwlock->thread_id));
 						//OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_HOLDER_FILE], innobase_basename(rwlock->file_name)));
-						//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE], rwlock->line));
+						//OK(fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->store(rwlock->line, true));
+						//fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->set_notnull();
 						OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_READERS], rw_lock_get_reader_count(rwlock)));
 						OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_WAITERS_FLAG], (longlong)rwlock->waiters));
 						OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LOCK_WORD], (longlong)rwlock->lock_word));
 						OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_LAST_READER_FILE], innobase_basename(rwlock->last_s_file_name)));
-						OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LAST_READER_LINE], rwlock->last_s_line));
+						OK(fields[SYS_SEMAPHORE_WAITS_LAST_READER_LINE]->store(rwlock->last_s_line, true));
+						fields[SYS_SEMAPHORE_WAITS_LAST_READER_LINE]->set_notnull();
 						OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_FILE], innobase_basename(rwlock->last_x_file_name)));
-						OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_LINE], rwlock->last_x_line));
+						OK(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_LINE]->store(rwlock->last_x_line, true));
+						fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_LINE]->set_notnull();
 						OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_OS_WAIT_COUNT], rwlock->count_os_wait));
 					}
 				}
diff --git a/storage/innobase/sync/sync0rw.cc b/storage/innobase/sync/sync0rw.cc
index 9160d9c8bee..5b2127b0c01 100644
--- a/storage/innobase/sync/sync0rw.cc
+++ b/storage/innobase/sync/sync0rw.cc
@@ -2,6 +2,7 @@
 
 Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 Portions of this file contain modifications contributed and copyrighted by
 Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -203,7 +204,7 @@ rw_lock_create_func(
 	latch_level_t	level,		/*!< in: level */
 #endif /* UNIV_DEBUG */
 	const char*	cfile_name,	/*!< in: file name where created */
-	ulint		cline)		/*!< in: file line where created */
+	unsigned	cline)		/*!< in: file line where created */
 {
 #if defined(UNIV_DEBUG) && !defined(UNIV_PFS_RWLOCK)
 	/* It should have been created in pfs_rw_lock_create_func() */
@@ -236,7 +237,7 @@ rw_lock_create_func(
 	split the source file anyway. Or create the locks on lines
 	less than 8192. cline is unsigned:13. */
 	ut_ad(cline <= 8192);
-	lock->cline = (unsigned int) cline;
+	lock->cline = cline;
 	lock->count_os_wait = 0;
 	lock->last_s_file_name = "not yet reserved";
 	lock->last_x_file_name = "not yet reserved";
@@ -295,7 +296,7 @@ rw_lock_s_lock_spin(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock
 				will be passed to another thread to unlock */
 	const char*	file_name, /*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	ulint		i = 0;	/* spin round count */
 	sync_array_t*	sync_arr;
@@ -425,7 +426,7 @@ rw_lock_x_lock_wait_func(
 #endif
 	lint		threshold,/*!< in: threshold to wait for */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	ulint		i = 0;
 	ulint		n_spins = 0;
@@ -520,7 +521,7 @@ rw_lock_x_lock_low(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	if (rw_lock_lock_word_decr(lock, X_LOCK_DECR, X_LOCK_HALF_DECR)) {
 
@@ -578,7 +579,7 @@ rw_lock_x_lock_low(
 	ut_d(rw_lock_add_debug_info(lock, pass, RW_LOCK_X, file_name, line));
 
 	lock->last_x_file_name = file_name;
-	lock->last_x_line = (unsigned int) line;
+	lock->last_x_line = line;
 
 	return(TRUE);
 }
@@ -593,7 +594,7 @@ rw_lock_sx_lock_low(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	if (rw_lock_lock_word_decr(lock, X_LOCK_HALF_DECR, X_LOCK_HALF_DECR)) {
 
@@ -652,7 +653,7 @@ rw_lock_sx_lock_low(
 	ut_d(rw_lock_add_debug_info(lock, pass, RW_LOCK_SX, file_name, line));
 
 	lock->last_x_file_name = file_name;
-	lock->last_x_line = (unsigned int) line;
+	lock->last_x_line = line;
 
 	return(TRUE);
 }
@@ -673,7 +674,7 @@ rw_lock_x_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 {
 	ulint		i = 0;
 	sync_array_t*	sync_arr;
@@ -775,7 +776,7 @@ rw_lock_sx_lock_func(
 	ulint		pass,	/*!< in: pass value; != 0, if the lock will
 				be passed to another thread to unlock */
 	const char*	file_name,/*!< in: file name where lock requested */
-	ulint		line)	/*!< in: line where requested */
+	unsigned	line)	/*!< in: line where requested */
 
 {
 	ulint		i = 0;
@@ -928,7 +929,7 @@ rw_lock_add_debug_info(
 	ulint		pass,		/*!< in: pass value */
 	ulint		lock_type,	/*!< in: lock type */
 	const char*	file_name,	/*!< in: file where requested */
-	ulint		line)		/*!< in: line where requested */
+	unsigned	line)		/*!< in: line where requested */
 {
 	ut_ad(file_name != NULL);
 
diff --git a/storage/innobase/ut/ut0dbg.cc b/storage/innobase/ut/ut0dbg.cc
index ed4a7778afa..d51eaa422ec 100644
--- a/storage/innobase/ut/ut0dbg.cc
+++ b/storage/innobase/ut/ut0dbg.cc
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -34,10 +35,10 @@ ut_dbg_assertion_failed(
 /*====================*/
 	const char* expr,	/*!< in: the failed assertion (optional) */
 	const char* file,	/*!< in: source file containing the assertion */
-	ulint line)		/*!< in: line number of the assertion */
+	unsigned line)		/*!< in: line number of the assertion */
 {
 	ut_print_timestamp(stderr);
-	fprintf(stderr, "  InnoDB: Assertion failure in file %s line %lu\n",
+	fprintf(stderr, "  InnoDB: Assertion failure in file %s line %u\n",
 		file, line);
 	if (expr) {
 		fprintf(stderr,
diff --git a/storage/maria/ma_blockrec.h b/storage/maria/ma_blockrec.h
index 3ea1fedf237..c33dfa0d5ea 100644
--- a/storage/maria/ma_blockrec.h
+++ b/storage/maria/ma_blockrec.h
@@ -50,8 +50,8 @@
 #define SUB_RANGE_SIZE		2
 #define BLOCK_FILLER_SIZE	2
 #define ROW_EXTENT_SIZE		(ROW_EXTENT_PAGE_SIZE + ROW_EXTENT_COUNT_SIZE)
-#define TAIL_BIT		0x8000	/* Bit in page_count to signify tail */
-#define START_EXTENT_BIT	0x4000	/* Bit in page_count to signify start*/
+#define TAIL_BIT		0x8000U	/* Bit in page_count to signify tail */
+#define START_EXTENT_BIT	0x4000U	/* Bit in page_count to signify start*/
 /* page_count set by bitmap code for tail pages */
 #define TAIL_PAGE_COUNT_MARKER  0xffff
 /* Number of extents reserved MARIA_BITMAP_BLOCKS to store head part */
@@ -75,7 +75,7 @@
 
 #define PAGE_TYPE_MASK 7
 enum en_page_type { UNALLOCATED_PAGE, HEAD_PAGE, TAIL_PAGE, BLOB_PAGE, MAX_PAGE_TYPE };
-#define PAGE_CAN_BE_COMPACTED   128             /* Bit in PAGE_TYPE */
+#define PAGE_CAN_BE_COMPACTED   128U            /* Bit in PAGE_TYPE */
 
 #define PAGE_TYPE_OFFSET        LSN_SIZE
 #define DIR_COUNT_OFFSET        (LSN_SIZE+PAGE_TYPE_SIZE)
@@ -86,12 +86,12 @@ enum en_page_type { UNALLOCATED_PAGE, HEAD_PAGE, TAIL_PAGE, BLOB_PAGE, MAX_PAGE_
 #define FULL_PAGE_KEY_VERSION_OFFSET (PAGE_TYPE_OFFSET + PAGE_TYPE_SIZE)
 
 /* Bits used for flag uchar (one byte, first in record) */
-#define ROW_FLAG_TRANSID                1
-#define ROW_FLAG_VER_PTR                2
-#define ROW_FLAG_DELETE_TRANSID         4
-#define ROW_FLAG_NULLS_EXTENDED         8
-#define ROW_FLAG_EXTENTS                128
-#define ROW_FLAG_ALL			(1+2+4+8+128)
+#define ROW_FLAG_TRANSID                1U
+#define ROW_FLAG_VER_PTR                2U
+#define ROW_FLAG_DELETE_TRANSID         4U
+#define ROW_FLAG_NULLS_EXTENDED         8U
+#define ROW_FLAG_EXTENTS                128U
+#define ROW_FLAG_ALL			(1U+2U+4U+8U+128U)
 
 /* Size for buffer to hold information about bitmap */
 #define MAX_BITMAP_INFO_LENGTH ((MARIA_MAX_KEY_BLOCK_LENGTH*8/3)*(61*11/60)+10)
@@ -99,8 +99,8 @@ enum en_page_type { UNALLOCATED_PAGE, HEAD_PAGE, TAIL_PAGE, BLOB_PAGE, MAX_PAGE_
 
 /******** Variables that affects how data pages are utilized ********/
 
-/* Minium size of tail segment */
-#define MIN_TAIL_SIZE           32
+/* Minimum size of tail segment */
+#define MIN_TAIL_SIZE           32U
 
 /*
   Fixed length part of Max possible header size; See row data structure
diff --git a/storage/maria/ma_loghandler.h b/storage/maria/ma_loghandler.h
index 5ac6d67413a..3719ec5e666 100644
--- a/storage/maria/ma_loghandler.h
+++ b/storage/maria/ma_loghandler.h
@@ -33,9 +33,9 @@
   We allow all kind protections to be switched on together for people who
   really unsure in their hardware/OS.
 */
-#define TRANSLOG_PAGE_CRC              1
-#define TRANSLOG_SECTOR_PROTECTION     (1<<1)
-#define TRANSLOG_RECORD_CRC            (1<<2)
+#define TRANSLOG_PAGE_CRC              1U
+#define TRANSLOG_SECTOR_PROTECTION     (1U<<1)
+#define TRANSLOG_RECORD_CRC            (1U<<2)
 #define TRANSLOG_FLAGS_NUM ((TRANSLOG_PAGE_CRC | TRANSLOG_SECTOR_PROTECTION | \
                            TRANSLOG_RECORD_CRC) + 1)
 
diff --git a/storage/maria/maria_chk.c b/storage/maria/maria_chk.c
index 0c1c56dfa94..0e347cbbd47 100644
--- a/storage/maria/maria_chk.c
+++ b/storage/maria/maria_chk.c
@@ -384,13 +384,13 @@ static struct my_option my_long_options[] =
     &check_param.read_buffer_length,
     &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
     (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
-    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
+    ~0ULL, (long) MALLOC_OVERHEAD, (long) 1L, 0},
   { "write_buffer_size", OPT_WRITE_BUFFER_SIZE,
     "Write buffer size for sequential writes during repair of fixed size or dynamic size rows",
     &check_param.write_buffer_length,
     &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
     (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
-    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
+    ~0UL, (long) MALLOC_OVERHEAD, (long) 1L, 0},
   { "sort_buffer_size", OPT_SORT_BUFFER_SIZE,
     "Size of sort buffer. Used by --recover",
     &check_param.sort_buffer_length,
diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h
index 19910f4288d..f3c66e87c46 100644
--- a/storage/maria/maria_def.h
+++ b/storage/maria/maria_def.h
@@ -710,49 +710,49 @@ struct st_maria_handler
 #define F_EXTRA_LCK	-1
 
 /* bits in opt_flag */
-#define MEMMAP_USED	32
-#define REMEMBER_OLD_POS 64
+#define MEMMAP_USED	32U
+#define REMEMBER_OLD_POS 64U
 
-#define WRITEINFO_UPDATE_KEYFILE	1
-#define WRITEINFO_NO_UNLOCK		2
+#define WRITEINFO_UPDATE_KEYFILE	1U
+#define WRITEINFO_NO_UNLOCK		2U
 
 /* once_flags */
-#define USE_PACKED_KEYS         1
-#define RRND_PRESERVE_LASTINX   2
+#define USE_PACKED_KEYS         1U
+#define RRND_PRESERVE_LASTINX   2U
 
 /* bits in state.changed */
 
-#define STATE_CHANGED		 1
-#define STATE_CRASHED		 2
-#define STATE_CRASHED_ON_REPAIR  4
-#define STATE_NOT_ANALYZED	 8
-#define STATE_NOT_OPTIMIZED_KEYS 16
-#define STATE_NOT_SORTED_PAGES	 32
-#define STATE_NOT_OPTIMIZED_ROWS 64
-#define STATE_NOT_ZEROFILLED     128
-#define STATE_NOT_MOVABLE        256
-#define STATE_MOVED              512 /* set if base->uuid != maria_uuid */
-#define STATE_IN_REPAIR  	 1024 /* We are running repair on table */
-#define STATE_CRASHED_PRINTED	 2048
+#define STATE_CHANGED		 1U
+#define STATE_CRASHED		 2U
+#define STATE_CRASHED_ON_REPAIR  4U
+#define STATE_NOT_ANALYZED	 8U
+#define STATE_NOT_OPTIMIZED_KEYS 16U
+#define STATE_NOT_SORTED_PAGES	 32U
+#define STATE_NOT_OPTIMIZED_ROWS 64U
+#define STATE_NOT_ZEROFILLED     128U
+#define STATE_NOT_MOVABLE        256U
+#define STATE_MOVED              512U /* set if base->uuid != maria_uuid */
+#define STATE_IN_REPAIR  	 1024U /* We are running repair on table */
+#define STATE_CRASHED_PRINTED	 2048U
 
 #define STATE_CRASHED_FLAGS (STATE_CRASHED | STATE_CRASHED_ON_REPAIR | STATE_CRASHED_PRINTED)
 
 /* options to maria_read_cache */
 
-#define READING_NEXT	1
-#define READING_HEADER	2
+#define READING_NEXT	1U
+#define READING_HEADER	2U
 
 /* Number of bytes on key pages to indicate used size */
-#define KEYPAGE_USED_SIZE  2
-#define KEYPAGE_KEYID_SIZE 1
-#define KEYPAGE_FLAG_SIZE  1
-#define KEYPAGE_KEY_VERSION_SIZE 4 /* encryption */
-#define KEYPAGE_CHECKSUM_SIZE 4
+#define KEYPAGE_USED_SIZE  2U
+#define KEYPAGE_KEYID_SIZE 1U
+#define KEYPAGE_FLAG_SIZE  1U
+#define KEYPAGE_KEY_VERSION_SIZE 4U /* encryption */
+#define KEYPAGE_CHECKSUM_SIZE 4U
 #define MAX_KEYPAGE_HEADER_SIZE (LSN_STORE_SIZE + KEYPAGE_USED_SIZE + \
                                  KEYPAGE_KEYID_SIZE + KEYPAGE_FLAG_SIZE + \
                                  TRANSID_SIZE + KEYPAGE_KEY_VERSION_SIZE)
-#define KEYPAGE_FLAG_ISNOD      1
-#define KEYPAGE_FLAG_HAS_TRANSID 2
+#define KEYPAGE_FLAG_ISNOD      1U
+#define KEYPAGE_FLAG_HAS_TRANSID 2U
 
 #define _ma_get_page_used(share,x) \
   ((uint) mi_uint2korr((x) + (share)->keypage_header - KEYPAGE_USED_SIZE))
@@ -886,9 +886,9 @@ struct st_maria_handler
 
 #define MEMMAP_EXTRA_MARGIN	7	/* Write this as a suffix for file */
 
-#define PACK_TYPE_SELECTED	1	/* Bits in field->pack_type */
-#define PACK_TYPE_SPACE_FIELDS	2
-#define PACK_TYPE_ZERO_FILL	4
+#define PACK_TYPE_SELECTED	1U	/* Bits in field->pack_type */
+#define PACK_TYPE_SPACE_FIELDS	2U
+#define PACK_TYPE_ZERO_FILL	4U
 #define MARIA_FOUND_WRONG_KEY 32738	/* Impossible value from ha_key_cmp */
 
 #define MARIA_BLOCK_SIZE(key_length,data_pointer,key_pointer,block_size)  (((((key_length)+(data_pointer)+(key_pointer))*4+(key_pointer)+2)/(block_size)+1)*(block_size))
@@ -911,12 +911,12 @@ extern mysql_mutex_t THR_LOCK_maria;
 
 /* Some tuning parameters */
 #define MARIA_MIN_KEYBLOCK_LENGTH 50	/* When to split delete blocks */
-#define MARIA_MIN_SIZE_BULK_INSERT_TREE 16384	/* this is per key */
+#define MARIA_MIN_SIZE_BULK_INSERT_TREE 16384U	/* this is per key */
 #define MARIA_MIN_ROWS_TO_USE_BULK_INSERT 100
 #define MARIA_MIN_ROWS_TO_DISABLE_INDEXES 100
 #define MARIA_MIN_ROWS_TO_USE_WRITE_CACHE 10
 /* Keep a small buffer for tables only using small blobs */
-#define MARIA_SMALL_BLOB_BUFFER 1024
+#define MARIA_SMALL_BLOB_BUFFER 1024U
 #define MARIA_MAX_CONTROL_FILE_LOCK_RETRY 30     /* Retry this many times */
 
 /* Some extern variables */
@@ -1247,12 +1247,12 @@ typedef struct st_maria_block_info
 
 /* bits in return from _ma_get_block_info */
 
-#define BLOCK_FIRST	1
-#define BLOCK_LAST	2
-#define BLOCK_DELETED	4
-#define BLOCK_ERROR	8			/* Wrong data */
-#define BLOCK_SYNC_ERROR 16			/* Right data at wrong place */
-#define BLOCK_FATAL_ERROR 32			/* hardware-error */
+#define BLOCK_FIRST	1U
+#define BLOCK_LAST	2U
+#define BLOCK_DELETED	4U
+#define BLOCK_ERROR	8U			/* Wrong data */
+#define BLOCK_SYNC_ERROR 16U			/* Right data at wrong place */
+#define BLOCK_FATAL_ERROR 32U			/* hardware-error */
 
 #define NEED_MEM	((uint) 10*4*(IO_SIZE+32)+32) /* Nead for recursion */
 #define MAXERR			20
@@ -1261,17 +1261,17 @@ typedef struct st_maria_block_info
 #define INDEX_TMP_EXT		".TMM"
 #define DATA_TMP_EXT		".TMD"
 
-#define UPDATE_TIME		1
-#define UPDATE_STAT		2
-#define UPDATE_SORT		4
-#define UPDATE_AUTO_INC		8
-#define UPDATE_OPEN_COUNT	16
+#define UPDATE_TIME		1U
+#define UPDATE_STAT		2U
+#define UPDATE_SORT		4U
+#define UPDATE_AUTO_INC		8U
+#define UPDATE_OPEN_COUNT	16U
 
 /* We use MY_ALIGN_DOWN here mainly to ensure that we get stable values for mysqld --help ) */
 #define PAGE_BUFFER_INIT	MY_ALIGN_DOWN(1024L*1024L*256L-MALLOC_OVERHEAD, 8192)
 #define READ_BUFFER_INIT	MY_ALIGN_DOWN(1024L*256L-MALLOC_OVERHEAD, 1024)
 #define SORT_BUFFER_INIT	MY_ALIGN_DOWN(1024L*1024L*256L-MALLOC_OVERHEAD, 1024)
-#define MIN_SORT_BUFFER		4096
+#define MIN_SORT_BUFFER		4096U
 
 #define fast_ma_writeinfo(INFO) if (!(INFO)->s->tot_locks) (void) _ma_writeinfo((INFO),0)
 #define fast_ma_readinfo(INFO) ((INFO)->lock_type == F_UNLCK) && _ma_readinfo((INFO),F_RDLCK,1)
diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h
index f467d44bcb9..8467daaafc3 100644
--- a/storage/myisam/myisamdef.h
+++ b/storage/myisam/myisamdef.h
@@ -1,5 +1,6 @@
 /*
    Copyright (c) 2000, 2012, Oracle and/or its affiliates.
+   Copyright (c) 2017, MariaDB Corporation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -92,16 +93,16 @@ typedef struct st_mi_state_info
 } MI_STATE_INFO;
 
 #define MI_STATE_INFO_SIZE      (24+14*8+7*4+2*2+8)
-#define MI_STATE_KEY_SIZE       8
-#define MI_STATE_KEYBLOCK_SIZE  8
-#define MI_STATE_KEYSEG_SIZE    4
+#define MI_STATE_KEY_SIZE       8U
+#define MI_STATE_KEYBLOCK_SIZE  8U
+#define MI_STATE_KEYSEG_SIZE    4U
 #define MI_STATE_EXTRA_SIZE ((MI_MAX_KEY+MI_MAX_KEY_BLOCK_SIZE)*MI_STATE_KEY_SIZE + MI_MAX_KEY*HA_MAX_KEY_SEG*MI_STATE_KEYSEG_SIZE)
 #define MI_KEYDEF_SIZE          (2+ 5*2)
 #define MI_UNIQUEDEF_SIZE       (2+1+1)
 #define HA_KEYSEG_SIZE          (6+ 2*2 + 4*2)
 #define MI_COLUMNDEF_SIZE       (2*3+1)
 #define MI_BASE_INFO_SIZE       (5*8 + 8*4 + 4 + 4*2 + 16)
-#define MI_INDEX_BLOCK_MARGIN   16      /* Safety margin for .MYI tables */
+#define MI_INDEX_BLOCK_MARGIN   16U      /* Safety margin for .MYI tables */
 
 typedef struct st_mi_base_info
 {
@@ -311,27 +312,27 @@ struct st_myisam_info
 #define USE_WHOLE_KEY   (HA_MAX_KEY_BUFF*2) /* Use whole key in _mi_search() */
 #define F_EXTRA_LCK     -1
 /* bits in opt_flag */
-#define MEMMAP_USED     32
-#define REMEMBER_OLD_POS 64
+#define MEMMAP_USED     32U
+#define REMEMBER_OLD_POS 64U
 
-#define WRITEINFO_UPDATE_KEYFILE        1
-#define WRITEINFO_NO_UNLOCK             2
+#define WRITEINFO_UPDATE_KEYFILE        1U
+#define WRITEINFO_NO_UNLOCK             2U
 
 /* once_flags */
-#define USE_PACKED_KEYS         1
-#define RRND_PRESERVE_LASTINX   2
+#define USE_PACKED_KEYS         1U
+#define RRND_PRESERVE_LASTINX   2U
 
 /* bits in state.changed */
-#define STATE_CHANGED           1
-#define STATE_CRASHED           2
-#define STATE_CRASHED_ON_REPAIR 4
-#define STATE_NOT_ANALYZED      8
-#define STATE_NOT_OPTIMIZED_KEYS 16
-#define STATE_NOT_SORTED_PAGES  32
+#define STATE_CHANGED           1U
+#define STATE_CRASHED           2U
+#define STATE_CRASHED_ON_REPAIR 4U
+#define STATE_NOT_ANALYZED      8U
+#define STATE_NOT_OPTIMIZED_KEYS 16U
+#define STATE_NOT_SORTED_PAGES  32U
 
 /* options to mi_read_cache */
-#define READING_NEXT    1
-#define READING_HEADER  2
+#define READING_NEXT    1U
+#define READING_HEADER  2U
 
 #define mi_getint(x)    ((uint) mi_uint2korr(x) & 32767)
 #define mi_putint(x,y,nod) { uint16 boh=(nod ? (uint16) 32768 : 0) + (uint16) (y);\
@@ -384,17 +385,17 @@ struct st_myisam_info
 #define MI_MAX_DYN_BLOCK_HEADER 20      /* Max prefix of record-block */
 #define MI_BLOCK_INFO_HEADER_LENGTH 20
 #define MI_DYN_DELETE_BLOCK_HEADER 20   /* length of delete-block-header */
-#define MI_DYN_MAX_BLOCK_LENGTH ((1L << 24)-4L)
+#define MI_DYN_MAX_BLOCK_LENGTH ((1UL << 24)-4UL)
 #define MI_DYN_MAX_ROW_LENGTH   (MI_DYN_MAX_BLOCK_LENGTH - MI_SPLIT_LENGTH)
-#define MI_DYN_ALIGN_SIZE       4       /* Align blocks on this */
+#define MI_DYN_ALIGN_SIZE       4U      /* Align blocks on this */
 #define MI_MAX_DYN_HEADER_BYTE  13      /* max header byte for dynamic rows */
-#define MI_MAX_BLOCK_LENGTH     ((((ulong) 1 << 24)-1) & (~ (ulong) (MI_DYN_ALIGN_SIZE-1)))
+#define MI_MAX_BLOCK_LENGTH     (((1U << 24)-1) & (~(MI_DYN_ALIGN_SIZE-1)))
 #define MI_REC_BUFF_OFFSET      ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER+sizeof(uint32))
 
 
-#define PACK_TYPE_SELECTED      1       /* Bits in field->pack_type */
-#define PACK_TYPE_SPACE_FIELDS  2
-#define PACK_TYPE_ZERO_FILL     4
+#define PACK_TYPE_SELECTED      1U      /* Bits in field->pack_type */
+#define PACK_TYPE_SPACE_FIELDS  2U
+#define PACK_TYPE_ZERO_FILL     4U
 #define MI_FOUND_WRONG_KEY 0x7FFFFFFF   /* Impossible value from ha_key_cmp */
 
 #define MI_MAX_KEY_BLOCK_SIZE   (MI_MAX_KEY_BLOCK_LENGTH/MI_MIN_KEY_BLOCK_LENGTH)
@@ -402,7 +403,7 @@ struct st_myisam_info
 #define MI_MAX_KEYPTR_SIZE      5       /* For calculating block lengths */
 #define MI_MIN_KEYBLOCK_LENGTH  50      /* When to split delete blocks */
 
-#define MI_MIN_SIZE_BULK_INSERT_TREE 16384 /* this is per key */
+#define MI_MIN_SIZE_BULK_INSERT_TREE 16384U /* this is per key */
 #define MI_MIN_ROWS_TO_USE_BULK_INSERT 100
 #define MI_MIN_ROWS_TO_DISABLE_INDEXES 100
 #define MI_MIN_ROWS_TO_USE_WRITE_CACHE 10
@@ -609,12 +610,12 @@ typedef struct st_mi_block_info         /* Parameter to _mi_get_block_info */
 
         /* bits in return from _mi_get_block_info */
 
-#define BLOCK_FIRST     1
-#define BLOCK_LAST      2
-#define BLOCK_DELETED   4
-#define BLOCK_ERROR     8               /* Wrong data */
-#define BLOCK_SYNC_ERROR 16             /* Right data at wrong place */
-#define BLOCK_FATAL_ERROR 32            /* hardware-error */
+#define BLOCK_FIRST     1U
+#define BLOCK_LAST      2U
+#define BLOCK_DELETED   4U
+#define BLOCK_ERROR     8U              /* Wrong data */
+#define BLOCK_SYNC_ERROR 16U            /* Right data at wrong place */
+#define BLOCK_FATAL_ERROR 32U           /* hardware-error */
 
 #define NEED_MEM        ((uint) 10*4*(IO_SIZE+32)+32) /* Nead for recursion */
 #define MAXERR                  20
@@ -623,17 +624,17 @@ typedef struct st_mi_block_info         /* Parameter to _mi_get_block_info */
 #define INDEX_TMP_EXT           ".TMM"
 #define DATA_TMP_EXT            ".TMD"
 
-#define UPDATE_TIME             1
-#define UPDATE_STAT             2
-#define UPDATE_SORT             4
-#define UPDATE_AUTO_INC         8
-#define UPDATE_OPEN_COUNT       16
+#define UPDATE_TIME             1U
+#define UPDATE_STAT             2U
+#define UPDATE_SORT             4U
+#define UPDATE_AUTO_INC         8U
+#define UPDATE_OPEN_COUNT       16U
 
 /* We use MY_ALIGN_DOWN here mainly to ensure that we get stable values for mysqld --help ) */
 #define KEY_BUFFER_INIT	        MY_ALIGN_DOWN(1024L*1024L-MALLOC_OVERHEAD, IO_SIZE)
 #define READ_BUFFER_INIT	MY_ALIGN_DOWN(1024L*256L-MALLOC_OVERHEAD, 1024)
 #define SORT_BUFFER_INIT	MY_ALIGN_DOWN(1024L*1024L*128L-MALLOC_OVERHEAD, 1024)
-#define MIN_SORT_BUFFER		4096
+#define MIN_SORT_BUFFER		4096U
 
 enum myisam_log_commands
 {
diff --git a/storage/perfschema/pfs_events_waits.h b/storage/perfschema/pfs_events_waits.h
index a7f7a095b9f..d65203e8614 100644
--- a/storage/perfschema/pfs_events_waits.h
+++ b/storage/perfschema/pfs_events_waits.h
@@ -1,4 +1,5 @@
 /* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2017, MariaDB Corporation. All rights reserved.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -97,13 +98,13 @@ struct PFS_events_waits : public PFS_events
 };
 
 /** TIMED bit in the state flags bitfield. */
-#define STATE_FLAG_TIMED (1<<0)
+#define STATE_FLAG_TIMED (1U<<0)
 /** THREAD bit in the state flags bitfield. */
-#define STATE_FLAG_THREAD (1<<1)
+#define STATE_FLAG_THREAD (1U<<1)
 /** EVENT bit in the state flags bitfield. */
-#define STATE_FLAG_EVENT (1<<2)
+#define STATE_FLAG_EVENT (1U<<2)
 /** DIGEST bit in the state flags bitfield. */
-#define STATE_FLAG_DIGEST (1<<3)
+#define STATE_FLAG_DIGEST (1U<<3)
 
 void insert_events_waits_history(PFS_thread *thread, PFS_events_waits *wait);
 
diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h
index 56dbc9ce0dc..929b9778556 100644
--- a/storage/spider/spd_db_include.h
+++ b/storage/spider/spd_db_include.h
@@ -182,32 +182,32 @@ typedef st_spider_result SPIDER_RESULT;
 #define SPIDER_SQL_LCL_NAME_QUOTE_STR "`"
 #define SPIDER_SQL_LCL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_LCL_NAME_QUOTE_STR) - 1)
 
-#define SPIDER_CONN_KIND_MYSQL (1 << 0)
+#define SPIDER_CONN_KIND_MYSQL (1U << 0)
 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
-#define SPIDER_CONN_KIND_HS_READ (1 << 2)
-#define SPIDER_CONN_KIND_HS_WRITE (1 << 3)
+#define SPIDER_CONN_KIND_HS_READ (1U << 2)
+#define SPIDER_CONN_KIND_HS_WRITE (1U << 3)
 #endif
 
-#define SPIDER_SQL_KIND_SQL (1 << 0)
-#define SPIDER_SQL_KIND_HANDLER (1 << 1)
+#define SPIDER_SQL_KIND_SQL (1U << 0)
+#define SPIDER_SQL_KIND_HANDLER (1U << 1)
 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
-#define SPIDER_SQL_KIND_HS (1 << 2)
+#define SPIDER_SQL_KIND_HS (1U << 2)
 #endif
 
-#define SPIDER_SQL_TYPE_SELECT_SQL (1 << 0)
-#define SPIDER_SQL_TYPE_INSERT_SQL (1 << 1)
-#define SPIDER_SQL_TYPE_UPDATE_SQL (1 << 2)
-#define SPIDER_SQL_TYPE_DELETE_SQL (1 << 3)
-#define SPIDER_SQL_TYPE_BULK_UPDATE_SQL (1 << 4)
-#define SPIDER_SQL_TYPE_TMP_SQL (1 << 5)
-#define SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL (1 << 6)
-#define SPIDER_SQL_TYPE_OTHER_SQL (1 << 7)
-#define SPIDER_SQL_TYPE_HANDLER (1 << 8)
-#define SPIDER_SQL_TYPE_SELECT_HS (1 << 9)
-#define SPIDER_SQL_TYPE_INSERT_HS (1 << 10)
-#define SPIDER_SQL_TYPE_UPDATE_HS (1 << 11)
-#define SPIDER_SQL_TYPE_DELETE_HS (1 << 12)
-#define SPIDER_SQL_TYPE_OTHER_HS (1 << 13)
+#define SPIDER_SQL_TYPE_SELECT_SQL (1U << 0)
+#define SPIDER_SQL_TYPE_INSERT_SQL (1U << 1)
+#define SPIDER_SQL_TYPE_UPDATE_SQL (1U << 2)
+#define SPIDER_SQL_TYPE_DELETE_SQL (1U << 3)
+#define SPIDER_SQL_TYPE_BULK_UPDATE_SQL (1U << 4)
+#define SPIDER_SQL_TYPE_TMP_SQL (1U << 5)
+#define SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL (1U << 6)
+#define SPIDER_SQL_TYPE_OTHER_SQL (1U << 7)
+#define SPIDER_SQL_TYPE_HANDLER (1U << 8)
+#define SPIDER_SQL_TYPE_SELECT_HS (1U << 9)
+#define SPIDER_SQL_TYPE_INSERT_HS (1U << 10)
+#define SPIDER_SQL_TYPE_UPDATE_HS (1U << 11)
+#define SPIDER_SQL_TYPE_DELETE_HS (1U << 12)
+#define SPIDER_SQL_TYPE_OTHER_HS (1U << 13)
 
 enum spider_bulk_upd_start {
   SPD_BU_NOT_START,


More information about the commits mailing list