apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject cvs commit: apr/strings apr_snprintf.c
Date Fri, 27 Apr 2001 13:02:00 GMT
martin      01/04/27 06:02:00

  Modified:    strings  apr_snprintf.c
  Log:
  Make ap_snprintf() more robust against border situations with
  floating point numbers.
  
  Submitted by:	Lukas Schroeder <lukas@edeal.de>
  
  Revision  Changes    Path
  1.13      +20 -10    apr/strings/apr_snprintf.c
  
  Index: apr_snprintf.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_snprintf.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -u -r1.12 -r1.13
  --- apr_snprintf.c	2001/02/25 20:39:37	1.12
  +++ apr_snprintf.c	2001/04/27 13:01:59	1.13
  @@ -157,7 +157,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++;
  @@ -954,15 +954,25 @@
   		/*
   		 * * 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 = ' ';
  +		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;
   
   
  
  
  

Mime
View raw message