[sheepdog] [PATCH] fix compiler warning in object_cache.c

Robin Dong robin.k.dong at gmail.com
Thu Aug 22 08:19:36 CEST 2013


When building sheepdog it reports warning message like:

	object_cache.c: In function ‘object_cache_flush_and_delete’:
	object_cache.c:1039: warning: comparison is always false due to limited range of data type
	object_cache.c: In function ‘load_cache_object’:
	object_cache.c:1252: warning: comparison is always false due to limited range of data type
	object_cache.c: In function ‘load_cache’:
	object_cache.c:1290: warning: comparison is always false due to limited range of data type

The 'idx' is the result of strtoul and it should be 'unsgiend long' instead of 'uint32_t' and
it can't reach ULLONG_MAX but ULONG_MAX.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 sheep/object_cache.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 3715a7c..6edc06a 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -1011,7 +1011,7 @@ static int object_cache_flush_and_delete(struct object_cache *oc)
 	DIR *dir;
 	struct dirent *d;
 	uint32_t vid = oc->vid;
-	uint32_t idx;
+	unsigned long idx;
 	uint64_t all = UINT64_MAX;
 	int ret = 0;
 	char p[PATH_MAX];
@@ -1036,7 +1036,7 @@ static int object_cache_flush_and_delete(struct object_cache *oc)
 		}
 
 		idx = strtoul(d->d_name, NULL, 16);
-		if (idx == ULLONG_MAX)
+		if (idx == ULONG_MAX)
 			continue;
 		if (push_cache_object(vid, idx, all, true) !=
 		    SD_RES_SUCCESS) {
@@ -1224,7 +1224,7 @@ static int load_cache_object(struct object_cache *cache)
 {
 	DIR *dir;
 	struct dirent *d;
-	uint32_t idx;
+	unsigned long idx;
 	char path[PATH_MAX];
 	int ret = 0;
 
@@ -1249,7 +1249,7 @@ static int load_cache_object(struct object_cache *cache)
 		}
 
 		idx = strtoul(d->d_name, NULL, 16);
-		if (idx == ULLONG_MAX)
+		if (idx == ULONG_MAX)
 			continue;
 
 		/*
@@ -1271,7 +1271,7 @@ static int load_cache(void)
 {
 	DIR *dir;
 	struct dirent *d;
-	uint32_t vid;
+	unsigned long vid;
 	char path[PATH_MAX];
 	int ret = 0;
 
@@ -1287,7 +1287,7 @@ static int load_cache(void)
 		if (!strncmp(d->d_name, ".", 1))
 			continue;
 		vid = strtoul(d->d_name, NULL, 16);
-		if (vid == ULLONG_MAX)
+		if (vid == ULONG_MAX)
 			continue;
 
 		load_cache_object(find_object_cache(vid, true));
-- 
1.7.3.2




More information about the sheepdog mailing list