From 4e2d70aff782ee3bc8289ffc04235337561ca8a5 Mon Sep 17 00:00:00 2001
From: GeorgyKirichenko <kirichenkoga@gmail.com>
Date: Fri, 22 Jan 2016 15:52:33 +0300
Subject: [PATCH] Fix compilation with Werror-sign for gcc-4.7. Issue #1283

---
 src/box/sophia_engine.cc |  2 +-
 src/lib/salad/bps_tree.h | 24 ++++++++++++------------
 src/lib/salad/rtree.c    |  3 ++-
 test/unit/bps_tree.cc    | 18 +++++++++---------
 test/unit/rtree.cc       |  2 +-
 5 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/src/box/sophia_engine.cc b/src/box/sophia_engine.cc
index 4731f67573..ceccefb981 100644
--- a/src/box/sophia_engine.cc
+++ b/src/box/sophia_engine.cc
@@ -486,7 +486,7 @@ SophiaEngine::keydefCheck(struct space *space, struct key_def *key_def)
 				  space_name(space),
 				  "Sophia TREE secondary indexes are not supported");
 		}
-		const int keypart_limit = 8;
+		const uint32_t keypart_limit = 8;
 		if (key_def->part_count > keypart_limit) {
 			tnt_raise(ClientError, ER_MODIFY_INDEX,
 			          key_def->name,
diff --git a/src/lib/salad/bps_tree.h b/src/lib/salad/bps_tree.h
index 648907e6e0..e9d3d1fb7f 100644
--- a/src/lib/salad/bps_tree.h
+++ b/src/lib/salad/bps_tree.h
@@ -4412,7 +4412,7 @@ bps_tree_debug_check_insert_into_leaf(struct bps_tree *tree, bool assertme)
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
 	for (unsigned int i = 0; i < szlim; i++) {
 		for (unsigned int j = 0; j <= i; j++) {
 			tree->size = 0;
@@ -4473,7 +4473,7 @@ bps_tree_debug_check_delete_from_leaf(struct bps_tree *tree, bool assertme)
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
 	for (unsigned int i = 1; i <= szlim; i++) {
 		for (unsigned int j = 0; j < i; j++) {
 			tree->size = 1;
@@ -4530,7 +4530,7 @@ bps_tree_debug_check_move_to_right_leaf(struct bps_tree *tree, bool assertme)
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
 	for (unsigned int i = 0; i <= szlim; i++) {
 		for (unsigned int j = 0; j <= szlim; j++) {
 			unsigned int max_move = i < szlim - j ? i : szlim - j;
@@ -4626,7 +4626,7 @@ bps_tree_debug_check_move_to_left_leaf(struct bps_tree *tree, bool assertme)
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
 	for (unsigned int i = 0; i <= szlim; i++) {
 		for (unsigned int j = 0; j <= szlim; j++) {
 			unsigned int max_move = j < szlim - i ? j : szlim - i;
@@ -4724,7 +4724,7 @@ bps_tree_debug_check_insert_and_move_to_right_leaf(struct bps_tree *tree,
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
 	for (unsigned int i = 0; i <= szlim; i++) {
 		for (unsigned int j = 0; j <= szlim; j++) {
 			unsigned int max_move =
@@ -4842,7 +4842,7 @@ bps_tree_debug_check_insert_and_move_to_left_leaf(struct bps_tree *tree,
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_LEAF;
 	for (unsigned int i = 0; i <= szlim; i++) {
 		for (unsigned int j = 0; j <= szlim; j++) {
 			unsigned int max_move =
@@ -4957,7 +4957,7 @@ bps_tree_debug_check_insert_into_inner(struct bps_tree *tree, bool assertme)
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
 	for (unsigned int i = 0; i < szlim; i++) {
 		for (unsigned int j = 0; j <= i; j++) {
 			tree->size = 0;
@@ -5027,7 +5027,7 @@ bps_tree_debug_check_delete_from_inner(struct bps_tree *tree, bool assertme)
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
 	for (unsigned int i = 1; i <= szlim; i++) {
 		for (unsigned int j = 0; j < i; j++) {
 			struct bps_inner block;
@@ -5081,7 +5081,7 @@ bps_tree_debug_check_move_to_right_inner(struct bps_tree *tree, bool assertme)
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
 	for (unsigned int i = 0; i <= szlim; i++) {
 		for (unsigned int j = 0; j <= szlim; j++) {
 			unsigned int max_move = i < szlim - j ? i : szlim - j;
@@ -5181,7 +5181,7 @@ bps_tree_debug_check_move_to_left_inner(struct bps_tree *tree, bool assertme)
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
 	for (unsigned int i = 0; i <= szlim; i++) {
 		for (unsigned int j = 0; j <= szlim; j++) {
 			unsigned int max_move = j < szlim - i ? j : szlim - i;
@@ -5282,7 +5282,7 @@ bps_tree_debug_check_insert_and_move_to_right_inner(struct bps_tree *tree,
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
 	for (unsigned int i = 0; i <= szlim; i++) {
 		for (unsigned int j = 0; j <= szlim; j++) {
 			unsigned int max_move =
@@ -5414,7 +5414,7 @@ bps_tree_debug_check_insert_and_move_to_left_inner(struct bps_tree *tree,
 {
 	(void) assertme;
 	int result = 0;
-	const int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
+	const unsigned int szlim = BPS_TREE_MAX_COUNT_IN_INNER;
 	for (unsigned int i = 0; i <= szlim; i++) {
 		for (unsigned int j = 0; j <= szlim; j++) {
 			unsigned int max_move =
diff --git a/src/lib/salad/rtree.c b/src/lib/salad/rtree.c
index d5d02cce2e..28fd8d6638 100644
--- a/src/lib/salad/rtree.c
+++ b/src/lib/salad/rtree.c
@@ -615,7 +615,7 @@ rtree_page_insert(struct rtree *tree, struct rtree_page *page,
 	struct rtree_page_branch br;
 	if (--level != 0) {
 		/* not a leaf page, minize area increase */
-		unsigned mini;
+		unsigned mini = 0;
 		char found = 0;
 		area_t min_incr = 0, best_area = 0;
 		for (unsigned i = 0; i < page->n; i++) {
@@ -638,6 +638,7 @@ rtree_page_insert(struct rtree *tree, struct rtree_page *page,
 			}
 		}
 		assert(found);
+		(void) found;
 		struct rtree_page_branch *b;
 		b = rtree_branch_get(tree, page, mini);
 		struct rtree_page *p = b->data.page;
diff --git a/test/unit/bps_tree.cc b/test/unit/bps_tree.cc
index 1a3e96dc38..1aa522dc3a 100644
--- a/test/unit/bps_tree.cc
+++ b/test/unit/bps_tree.cc
@@ -84,12 +84,12 @@ simple_check()
 {
 	header();
 
-	const int rounds = 2000;
+	const unsigned int rounds = 2000;
 	bps_tree_test tree;
 	bps_tree_test_create(&tree, 0, extent_alloc, extent_free);
 
 	printf("Insert 1..X, remove 1..X\n");
-	for (int i = 0; i < rounds; i++) {
+	for (unsigned int i = 0; i < rounds; i++) {
 		type_t v = i;
 		if (bps_tree_test_find(&tree, v) != NULL)
 			fail("element already in tree (1)", "true");
@@ -102,7 +102,7 @@ simple_check()
 	if (bps_tree_test_size(&tree) != rounds)
 		fail("Tree count mismatch (1)", "true");
 
-	for (int i = 0; i < rounds; i++) {
+	for (unsigned int i = 0; i < rounds; i++) {
 		type_t v = i;
 		if (bps_tree_test_find(&tree, v) == NULL)
 			fail("element in tree (1)", "false");
@@ -116,7 +116,7 @@ simple_check()
 		fail("Tree count mismatch (2)", "true");
 
 	printf("Insert 1..X, remove X..1\n");
-	for (int i = 0; i < rounds; i++) {
+	for (unsigned int i = 0; i < rounds; i++) {
 		type_t v = i;
 		if (bps_tree_test_find(&tree, v) != NULL)
 			fail("element already in tree (2)", "true");
@@ -129,7 +129,7 @@ simple_check()
 	if (bps_tree_test_size(&tree) != rounds)
 		fail("Tree count mismatch (3)", "true");
 
-	for (int i = 0; i < rounds; i++) {
+	for (unsigned int i = 0; i < rounds; i++) {
 		type_t v = rounds - 1 - i;
 		if (bps_tree_test_find(&tree, v) == NULL)
 			fail("element in tree (2)", "false");
@@ -143,7 +143,7 @@ simple_check()
 		fail("Tree count mismatch (4)", "true");
 
 	printf("Insert X..1, remove 1..X\n");
-	for (int i = 0; i < rounds; i++) {
+	for (unsigned int i = 0; i < rounds; i++) {
 		type_t v = rounds - 1 - i;
 		if (bps_tree_test_find(&tree, v) != NULL)
 			fail("element already in tree (3)", "true");
@@ -156,7 +156,7 @@ simple_check()
 	if (bps_tree_test_size(&tree) != rounds)
 		fail("Tree count mismatch (5)", "true");
 
-	for (int i = 0; i < rounds; i++) {
+	for (unsigned int i = 0; i < rounds; i++) {
 		type_t v = i;
 		if (bps_tree_test_find(&tree, v) == NULL)
 			fail("element in tree (3)", "false");
@@ -170,7 +170,7 @@ simple_check()
 		fail("Tree count mismatch (6)", "true");
 
 	printf("Insert X..1, remove X..1\n");
-	for (int i = 0; i < rounds; i++) {
+	for (unsigned int i = 0; i < rounds; i++) {
 		type_t v = rounds - 1 - i;
 		if (bps_tree_test_find(&tree, v) != NULL)
 			fail("element already in tree (4)", "true");
@@ -183,7 +183,7 @@ simple_check()
 	if (bps_tree_test_size(&tree) != rounds)
 		fail("Tree count mismatch (7)", "true");
 
-	for (int i = 0; i < rounds; i++) {
+	for (unsigned int i = 0; i < rounds; i++) {
 		type_t v = rounds - 1 - i;
 		if (bps_tree_test_find(&tree, v) == NULL)
 			fail("element in tree (4)", "false");
diff --git a/test/unit/rtree.cc b/test/unit/rtree.cc
index 11497c4171..6d482dc63e 100644
--- a/test/unit/rtree.cc
+++ b/test/unit/rtree.cc
@@ -219,7 +219,7 @@ neighbor_test()
 {
 	header();
 
-	const int test_count = 1000;
+	const unsigned int test_count = 1000;
 	struct rtree_rect arr[test_count];
 	static struct rtree_rect basis;
 
-- 
GitLab