You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ma...@apache.org on 2001/04/27 15:01:30 UTC
cvs commit: apache-1.3/src/ap ap_snprintf.c
martin 01/04/27 06:01:30
Modified: src/ap ap_snprintf.c
Log:
Make ap_snprintf() more robust against border situations with
floating point numbers.
Submitted by: Lukas Schroeder <lu...@edeal.de>
Revision Changes Path
1.44 +21 -11 apache-1.3/src/ap/ap_snprintf.c
Index: ap_snprintf.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/ap/ap_snprintf.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -u -r1.43 -r1.44
--- ap_snprintf.c 2001/01/15 17:04:14 1.43
+++ ap_snprintf.c 2001/04/27 13:01:28 1.44
@@ -152,7 +152,7 @@
*/
if (fi != 0) {
p1 = &buf[NDIG];
- while (fi != 0) {
+ while (p1 > &buf[0] && fi != 0) {
fj = modf(fi / 10, &fi);
*--p1 = (int) ((fj + .03) * 10) + '0';
r2++;
@@ -931,16 +931,26 @@
/*
* * We use &num_buf[ 1 ], so that we have room for the sign
*/
- 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;
+ if (isnan(fp_num)) {
+ s = "nan";
+ s_len = 3;
+ }
+ else if (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;
case 'g':