comparison src/core/ngx_string.c @ 672:f41d4b305d22 NGINX_1_2_0

nginx 1.2.0 *) Bugfix: a segmentation fault might occur in a worker process if the "try_files" directive was used; the bug had appeared in 1.1.19. *) Bugfix: response might be truncated if there were more than IOV_MAX buffers used. *) Bugfix: in the "crop" parameter of the "image_filter" directive. Thanks to Maxim Bublis.
author Igor Sysoev <http://sysoev.ru>
date Mon, 23 Apr 2012 00:00:00 +0400
parents d0f7a625f27c
children 660139fd80ca
comparison
equal deleted inserted replaced
671:47cb3497fbab 672:f41d4b305d22
144 u_char * 144 u_char *
145 ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args) 145 ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args)
146 { 146 {
147 u_char *p, zero; 147 u_char *p, zero;
148 int d; 148 int d;
149 double f, scale; 149 double f;
150 size_t len, slen; 150 size_t len, slen;
151 int64_t i64; 151 int64_t i64;
152 uint64_t ui64; 152 uint64_t ui64, frac;
153 ngx_msec_t ms; 153 ngx_msec_t ms;
154 ngx_uint_t width, sign, hex, max_width, frac_width, n; 154 ngx_uint_t width, sign, hex, max_width, frac_width, scale, n;
155 ngx_str_t *v; 155 ngx_str_t *v;
156 ngx_variable_value_t *vv; 156 ngx_variable_value_t *vv;
157 157
158 while (*fmt && buf < last) { 158 while (*fmt && buf < last) {
159 159
363 *buf++ = '-'; 363 *buf++ = '-';
364 f = -f; 364 f = -f;
365 } 365 }
366 366
367 ui64 = (int64_t) f; 367 ui64 = (int64_t) f;
368 frac = 0;
369
370 if (frac_width) {
371
372 scale = 1;
373 for (n = frac_width; n; n--) {
374 scale *= 10;
375 }
376
377 frac = (uint64_t) ((f - (double) ui64) * scale + 0.5);
378
379 if (frac == scale) {
380 ui64++;
381 frac = 0;
382 }
383 }
368 384
369 buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width); 385 buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);
370 386
371 if (frac_width) { 387 if (frac_width) {
372
373 if (buf < last) { 388 if (buf < last) {
374 *buf++ = '.'; 389 *buf++ = '.';
375 } 390 }
376 391
377 scale = 1.0; 392 buf = ngx_sprintf_num(buf, last, frac, '0', 0, frac_width);
378
379 for (n = frac_width; n; n--) {
380 scale *= 10.0;
381 }
382
383 /*
384 * (int64_t) cast is required for msvc6:
385 * it cannot convert uint64_t to double
386 */
387 ui64 = (uint64_t) ((f - (int64_t) ui64) * scale + 0.5);
388
389 buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);
390 } 393 }
391 394
392 fmt++; 395 fmt++;
393 396
394 continue; 397 continue;