From: Andi Gutmans Date: Tue, 1 May 2001 16:29:52 +0000 (+0000) Subject: - Fix snprintf() to work with nan and inf properly X-Git-Tag: php-4.0.6RC1~213 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d04562e84552fbdd9444a26a98e85ba78287b425;p=php - Fix snprintf() to work with nan and inf properly --- diff --git a/main/snprintf.c b/main/snprintf.c index b3afec1146..e4d42d5fff 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -112,7 +112,8 @@ static char * */ if (fi != 0) { p1 = &buf[NDIG]; - while (fi != 0) { +// while (fi != 0) { + while (p1 > &buf[0] && fi != 0) { fj = modf(fi / 10, &fi); *--p1 = (int) ((fj + .03) * 10) + '0'; r2++; @@ -743,15 +744,23 @@ static int format_converter(register buffy * odp, const char *fmt, case 'E': fp_num = va_arg(ap, double); - s = conv_fp(*fmt, fp_num, alternate_form, - (adjust_precision == NO) ? FLOAT_DIGITS : precision, - &is_negative, &num_buf[1], &s_len); - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; + if (zend_isnan(fp_num)) { + s = "nan"; + s_len = 3; + } else if (zend_isinf(fp_num)) { + s = "inf"; + s_len = 3; + } else { + s = conv_fp(*fmt, fp_num, alternate_form, + (adjust_precision == NO) ? FLOAT_DIGITS : precision, + &is_negative, &num_buf[1], &s_len); + if (is_negative) + prefix_char = '-'; + else if (print_sign) + prefix_char = '+'; + else if (print_blank) + prefix_char = ' '; + } break;