[sheepdog] [PATCH] fix uninitialized variable access in xqsort and xbsearch
Liu Yuan
namei.unix at gmail.com
Fri May 31 05:23:20 CEST 2013
On 05/30/2013 10:21 PM, MORITA Kazutaka wrote:
> 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); \
> })
>
>
Applied, thanks.
Yuan
More information about the sheepdog
mailing list