From 328df7a5cc91180fef3b1b58129e14bc79bef80b Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Fri, 14 May 2010 09:55:33 +0000 Subject: [PATCH] use ngx_min() and ngx_max() --- src/core/ngx_output_chain.c | 5 +---- src/core/ngx_string.c | 11 +++-------- src/http/modules/ngx_http_log_module.c | 2 +- src/http/ngx_http_upstream.c | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c index 3ff25ff76..f51d69000 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -465,10 +465,7 @@ ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx) dst = ctx->buf; size = ngx_buf_size(src); - - if (size > dst->end - dst->pos) { - size = dst->end - dst->pos; - } + size = ngx_min(size, dst->end - dst->pos); sendfile = ctx->sendfile & !ctx->directio; diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c index f513753a1..95ac9cbff 100644 --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -229,9 +229,7 @@ ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args) case 'V': v = va_arg(args, ngx_str_t *); - len = v->len; - len = (buf + len < last) ? len : (size_t) (last - buf); - + len = ngx_min(((size_t) (last - buf)), v->len); buf = ngx_cpymem(buf, v->data, len); fmt++; @@ -240,9 +238,7 @@ ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args) case 'v': vv = va_arg(args, ngx_variable_value_t *); - len = vv->len; - len = (buf + len < last) ? len : (size_t) (last - buf); - + len = ngx_min(((size_t) (last - buf)), vv->len); buf = ngx_cpymem(buf, vv->data, len); fmt++; @@ -257,8 +253,7 @@ ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args) } } else { - len = (buf + slen < last) ? slen : (size_t) (last - buf); - + len = ngx_min(((size_t) (last - buf)), slen); buf = ngx_cpymem(buf, p, len); } diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c index 0752d0394..1796ee27f 100644 --- a/src/http/modules/ngx_http_log_module.c +++ b/src/http/modules/ngx_http_log_module.c @@ -533,7 +533,7 @@ ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, ms = (ngx_msec_int_t) ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); - ms = (ms >= 0) ? ms : 0; + ms = ngx_max(ms, 0); return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000); } diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 273d3575e..522a60536 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -3710,7 +3710,7 @@ ngx_http_upstream_response_time_variable(ngx_http_request_t *r, if (state[i].status) { ms = (ngx_msec_int_t) (state[i].response_sec * 1000 + state[i].response_msec); - ms = (ms >= 0) ? ms : 0; + ms = ngx_max(ms, 0); p = ngx_sprintf(p, "%d.%03d", ms / 1000, ms % 1000); } else {