test-cmap: Avoid shift by full width of type in find_batch().
In C, it is undefined to shift an N-bit value by N.  This fixes the
problem in find_batch() for the case where i == 0.
Found by Coverity.
Reported-at:
Acked-by: Justin Pettit
/*
- * Copyright (c) 2008, 2009, 2010, 2013, 2014, 2016 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2013, 2014, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -412,7 +412,6 @@ find_batch(const struct cmap *cmap, const int value)
{
size_t i, ret;
const size_t end = MIN(n_batch, n_elems - value);
- unsigned long map = ~0;
uint32_t hashes[N_BATCH_MAX];
const struct cmap_node *nodes[N_BATCH_MAX];
@@ -431,7 +430,7 @@ find_batch(const struct cmap *cmap, const int value)
ret = i;
- map >>= BITMAP_ULONG_BITS - i; /* Clear excess bits. */
+ unsigned long map = i ? ~0UL >> (BITMAP_ULONG_BITS - i) : 0;
map = cmap_find_batch(cmap, map, hashes, nodes);
ULLONG_FOR_EACH_1(i, map) {
