r2919 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Thu Jul 10 20:09:42 CEST 2008
Author: phk
Date: 2008-07-10 20:09:42 +0200 (Thu, 10 Jul 2008)
New Revision: 2919
Modified:
trunk/varnish-cache/bin/varnishd/cache_dir_random.c
Log:
Fix an off-by one in the random director
Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-10 18:08:42 UTC (rev 2918)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-10 18:09:42 UTC (rev 2919)
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -74,7 +75,7 @@
r = random();
r &= 0x7fffffff;
- for (vh = vs->hosts; i < vs->nhosts; vh++)
+ for (i = 0, vh = vs->hosts; i < vs->nhosts; vh++)
if (r < vh->weight)
return (vh->backend);
assert(0 == __LINE__);
@@ -136,7 +137,7 @@
i = 0;
a = 0.0;
assert(s > 0.0);
- for (te = t->members; te->host != NULL; te++, i++) {
+ for (te = t->members; i < t->nmember; te++, i++) {
/* First normalize the specified weight in FP */
b = te->weight / s; /*lint !e795 not zero division */
/* Then accumulate to eliminate rounding errors */
@@ -145,5 +146,6 @@
v = (unsigned)((1U<<31) * a);
vs->hosts[i].weight = v;
}
+ assert(vs->hosts[t->nmember - 1].weight > 0x7fffffff);
*bp = &vs->dir;
}
More information about the varnish-commit
mailing list