aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_split_clients_module.c
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@nginx.com>2012-03-28 06:50:23 +0000
committerRuslan Ermilov <ru@nginx.com>2012-03-28 06:50:23 +0000
commit52fcfd042e6c15fc33d05b554245b8cf31a59e14 (patch)
treec179f7c27a7de4baa043fa98876c8f385233e5e6 /src/http/modules/ngx_http_split_clients_module.c
parent5d5c866beecb70fcb5a746f59bd0a4c810b09663 (diff)
downloadnginx-52fcfd042e6c15fc33d05b554245b8cf31a59e14.tar.gz
nginx-52fcfd042e6c15fc33d05b554245b8cf31a59e14.zip
Fixed calculation of range boundaries.
Diffstat (limited to 'src/http/modules/ngx_http_split_clients_module.c')
-rw-r--r--src/http/modules/ngx_http_split_clients_module.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/http/modules/ngx_http_split_clients_module.c b/src/http/modules/ngx_http_split_clients_module.c
index f2160b149..6b1a8155a 100644
--- a/src/http/modules/ngx_http_split_clients_module.c
+++ b/src/http/modules/ngx_http_split_clients_module.c
@@ -97,7 +97,7 @@ ngx_http_split_clients_variable(ngx_http_request_t *r,
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http split: %uD %uD", hash, part[i].percent);
- if (hash < part[i].percent) {
+ if (hash < part[i].percent || part[i].percent == 0) {
*v = part[i].value;
return NGX_OK;
}
@@ -111,8 +111,9 @@ static char *
ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *rv;
+ uint32_t sum, last;
ngx_str_t *value, name;
- ngx_uint_t i, sum, last;
+ ngx_uint_t i;
ngx_conf_t save;
ngx_http_variable_t *var;
ngx_http_split_clients_ctx_t *ctx;
@@ -175,19 +176,15 @@ ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (i = 0; i < ctx->parts.nelts; i++) {
sum = part[i].percent ? sum + part[i].percent : 10000;
if (sum > 10000) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "percent sum is more than 100%%");
- return NGX_CONF_ERROR;
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "percent sum is more than 100%%");
+ return NGX_CONF_ERROR;
}
if (part[i].percent) {
- part[i].percent = (uint32_t)
- (last + 0xffffffff / 10000 * part[i].percent);
- } else {
- part[i].percent = 0xffffffff;
+ last += part[i].percent * (uint64_t) 0xffffffff / 10000;
+ part[i].percent = last;
}
-
- last = part[i].percent;
}
return rv;