[sheepdog] [PATCH] fix uninitialized variable access in xqsort and xbsearch

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu May 30 16:21:09 CEST 2013


This silences valgrind errors.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/util.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/util.h b/include/util.h
index 8b7634f..1c42ff8 100644
--- a/include/util.h
+++ b/include/util.h
@@ -102,15 +102,18 @@ int atomic_create_and_write(const char *path, char *buf, size_t len);
 /* a type safe version of qsort() */
 #define xqsort(base, nmemb, compar)					\
 ({									\
-	assert(compar(base, base) == 0);				\
-	qsort(base, nmemb, sizeof(*(base)), (comparison_fn_t)compar);	\
+	if (nmemb > 1) {						\
+		qsort(base, nmemb, sizeof(*(base)),			\
+		      (comparison_fn_t)compar);				\
+		assert(compar(base, base + 1) <= 0);			\
+	}								\
 })
 
 /* a type safe version of bsearch() */
 #define xbsearch(key, base, nmemb, compar)				\
 ({									\
 	(void) (key == base);						\
-	assert(compar(base, base) == 0);				\
+	assert(compar(key, key) == 0);					\
 	bsearch(key, base, nmemb, sizeof(*(base)), (comparison_fn_t)compar); \
 })
 
-- 
1.8.1.3.566.gaa39828




More information about the sheepdog mailing list