Browse Source

- Fix snprintf() to work with nan and inf properly

PHP-4.0.6
Andi Gutmans 25 years ago
parent
commit
d04562e845
  1. 29
      main/snprintf.c

29
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;

Loading…
Cancel
Save