[master] 65c8593 Fix boundary condition on an assert.

Poul-Henning Kamp phk at varnish-cache.org
Mon Jul 15 10:26:01 CEST 2013


commit 65c8593dc828b0ac6944d3897cf33d64028c6c43
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jul 15 08:25:19 2013 +0000

    Fix boundary condition on an assert.
    
    Fixes #1324

diff --git a/lib/libvmod_directors/hash.c b/lib/libvmod_directors/hash.c
index 43b4872..290909f 100644
--- a/lib/libvmod_directors/hash.c
+++ b/lib/libvmod_directors/hash.c
@@ -118,6 +118,7 @@ vmod_hash_backend(const struct vrt_ctx *ctx, struct vmod_directors_hash *rr,
 
 	r = vbe32dec(sha256);
 	r = scalbn(r, -32);
+	assert(r >= 0 && r <= 1.0);
 	be = vdir_pick_be(rr->vd, ctx->bo, r, rr->nloops);
 	return (be);
 }
diff --git a/lib/libvmod_directors/random.c b/lib/libvmod_directors/random.c
index a8dd8a7..6d2be1e 100644
--- a/lib/libvmod_directors/random.c
+++ b/lib/libvmod_directors/random.c
@@ -67,6 +67,7 @@ vmod_rr_getfd(const struct director *dir, struct busyobj *bo)
 
 	CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);
 	r = scalbn(random(), -31);
+	assert(r >= 0 && r < 1.0);
 	be = vdir_pick_be(rr->vd, bo, r, rr->nloops);
 	if (be == NULL)
 		return (NULL);
diff --git a/lib/libvmod_directors/vdir.c b/lib/libvmod_directors/vdir.c
index 62b0033..14d523d 100644
--- a/lib/libvmod_directors/vdir.c
+++ b/lib/libvmod_directors/vdir.c
@@ -180,7 +180,7 @@ vdir_pick_be(struct vdir *vd, const struct busyobj *bo, double w,
 
 	tw = vd->total_weight;
 	nbe = vd->n_backend;
-	assert(w >= 0.0 && w <= 1.0);
+	assert(w >= 0.0 && w < 1.0);
 	vdir_lock(vd);
 	for (l = 0; nbe > 0 && tw > 0.0 && l <nloops; l++) {
 		u = vdir_pick_by_weight(vd, w * tw, vbm);



More information about the varnish-commit mailing list