This avoids a divide by zero when the input and/or map are
malformed.
Signed-off-by: Sage Weil <sage@newdream.net>
struct crush_bucket *in = bucket;
int r;
int i;
- int item;
+ int item = 0;
int itemtype;
int collide, reject;
const int orig_tries = 5; /* attempts before we fall back to search */
/* choose through intervening buckets */
flocal = 0;
do {
+ collide = 0;
retry_bucket = 0;
r = rep;
if (in->alg == CRUSH_BUCKET_UNIFORM) {
}
/* bucket choose */
+ if (in->size == 0) {
+ reject = 1;
+ goto reject;
+ }
if (flocal >= (in->size>>1) &&
flocal > orig_tries)
item = bucket_perm_choose(in, x, r);
}
/* collision? */
- collide = 0;
for (i = 0; i < outpos; i++) {
if (out[i] == item) {
collide = 1;
reject = 0;
}
+reject:
if (reject || collide) {
ftotal++;
flocal++;