diff --git a/CMakeLists.txt b/CMakeLists.txt
index d2b6162ba26904d6355475b8072e8f219724073c..47b1a566cd84439438aaede423ef02577df18f10 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,18 +15,16 @@
 
 SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
-ADD_DEFINITIONS(-DMYSQL_SERVER -D_WIN32 -DWIN32 -D_LIB)
-IF(EMBEDDED_ONLY)
-  ADD_DEFINITIONS(-DUSE_TLS)
-ENDIF(EMBEDDED_ONLY)
+ADD_DEFINITIONS(-DMYSQL_SERVER -D_WIN32 -D_LIB)
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib
-                    include
-                    handler
+                    ${CMAKE_SOURCE_DIR}/storage/innobase/include
+                    ${CMAKE_SOURCE_DIR}/storage/innobase/handler
                     ${CMAKE_SOURCE_DIR}/sql
                     ${CMAKE_SOURCE_DIR}/regex
                     ${CMAKE_SOURCE_DIR}/extra/yassl/include)
-ADD_LIBRARY(innobase btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c btr/btr0sea.c 
+
+SET(INNOBASE_SOURCES  btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c btr/btr0sea.c 
 					 buf/buf0buf.c buf/buf0flu.c buf/buf0lru.c buf/buf0rea.c 
 					 data/data0data.c data/data0type.c 
 					 dict/dict0boot.c dict/dict0crea.c dict/dict0dict.c dict/dict0load.c dict/dict0mem.c 
@@ -57,3 +55,7 @@ ADD_LIBRARY(innobase btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c btr/btr0sea.c
 					 trx/trx0purge.c trx/trx0rec.c trx/trx0roll.c trx/trx0rseg.c trx/trx0sys.c trx/trx0trx.c trx/trx0undo.c 
 					 usr/usr0sess.c 
 					 ut/ut0byte.c ut/ut0dbg.c ut/ut0mem.c ut/ut0rnd.c ut/ut0ut.c ut/ut0vec.c ut/ut0list.c ut/ut0wqueue.c)
+
+IF(NOT SOURCE_SUBLIBS)
+  ADD_LIBRARY(innobase ${INNOBASE_SOURCES})
+ENDIF(NOT SOURCE_SUBLIBS)
diff --git a/dict/dict0dict.c b/dict/dict0dict.c
index 0ecd0b4e1ab1458f0af9a6e8ea4d928876851566..52ca40c21ac3e9da0feca379d523a25c12731d0b 100644
--- a/dict/dict0dict.c
+++ b/dict/dict0dict.c
@@ -378,6 +378,8 @@ dict_table_autoinc_initialize(
 	dict_table_t*	table,	/* in/out: table */
 	ib_longlong	value)	/* in: next value to assign to a row */
 {
+	ut_ad(mutex_own(&table->autoinc_mutex));
+
 	table->autoinc_inited = TRUE;
 	table->autoinc = value;
 }
@@ -394,6 +396,8 @@ dict_table_autoinc_read(
 {
 	ib_longlong	value;
 
+	ut_ad(mutex_own(&table->autoinc_mutex));
+
 	if (!table->autoinc_inited) {
 
 		value = 0;
diff --git a/dict/dict0mem.c b/dict/dict0mem.c
index 3a39351272bb3bb8c4aa7b5288e00a974296cedf..d33e9ac5f7da1036793cd660d39789aec8e76694 100644
--- a/dict/dict0mem.c
+++ b/dict/dict0mem.c
@@ -174,7 +174,7 @@ dict_mem_table_add_col(
 
 	col = dict_table_get_nth_col(table, i);
 
-	col->ind = i;
+	col->ind = (unsigned int) i;
 	col->ord_part = 0;
 
 	col->mtype = (unsigned int) mtype;
diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc
index bfa0bb2537cef944a8b1d92ae3e453d55ed90b27..bcee94f61c211c39396158300c82785730f32520 100644
--- a/handler/ha_innodb.cc
+++ b/handler/ha_innodb.cc
@@ -5852,7 +5852,7 @@ ha_innobase::info(
 
 				table->key_info[i].rec_per_key[j]=
 				  rec_per_key >= ~(ulong) 0 ? ~(ulong) 0 :
-				  rec_per_key;
+				  (ulong) rec_per_key;
 			}
 
 			index = dict_table_get_next_index(index);
@@ -7318,7 +7318,7 @@ ha_innobase::innobase_get_auto_increment(
 /*=====================================*/
 	ulonglong*	value)		/* out: autoinc value */
 {
-	ulint		error;
+	ulong		error;
 
 	*value = 0;
 
@@ -7428,7 +7428,7 @@ ha_innobase::get_auto_increment(
 	/* Called for the first time ? */
 	if (trx->n_autoinc_rows == 0) {
 
-		trx->n_autoinc_rows = nb_desired_values;
+		trx->n_autoinc_rows = (ulint) nb_desired_values;
 
 		/* It's possible for nb_desired_values to be 0:
 		e.g., INSERT INTO T1(C) SELECT C FROM T2; */
diff --git a/row/row0mysql.c b/row/row0mysql.c
index c4f1572a3ac7319ea0b1ee911fd4124d46493f58..5a636b3df99e0584904335823cbb1a4a9255dd1a 100644
--- a/row/row0mysql.c
+++ b/row/row0mysql.c
@@ -3020,7 +3020,9 @@ row_truncate_table_for_mysql(
 
 	/* MySQL calls ha_innobase::reset_auto_increment() which does
 	the same thing. */
+	dict_table_autoinc_lock(table);
 	dict_table_autoinc_initialize(table, 0);
+	dict_table_autoinc_unlock(table);
 	dict_update_statistics(table);
 
 	trx_commit_for_mysql(trx);
diff --git a/ut/ut0ut.c b/ut/ut0ut.c
index 1ec20980e1f0ac8a22b3d7eeceb573aad47e007e..53048c87af345a6debb84014e58fd5cd65f10dc1 100644
--- a/ut/ut0ut.c
+++ b/ut/ut0ut.c
@@ -537,15 +537,12 @@ ut_snprintf(
 	va_start(ap2, fmt);
 
 	res = _vscprintf(fmt, ap1);
-
-	if (res == -1) {
-		return(-1);
-	}
+	ut_a(res != -1);
 
 	if (size > 0) {
 		_vsnprintf(str, size, fmt, ap2);
 
-		if ((size_t)res >= size) {
+		if ((size_t) res >= size) {
 			str[size - 1] = '\0';
 		}
 	}