summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authormartin <martin@13f79535-47bb-0310-9956-ffa450edef68>2001-04-27 13:01:59 +0000
committermartin <martin@13f79535-47bb-0310-9956-ffa450edef68>2001-04-27 13:01:59 +0000
commit5f431437bc3ac26739e8fc8b175848baee9c0327 (patch)
tree17ae2a38e7b772499d80bb37722ed46e7db50886 /strings
parent0803b471a1acd950beef7c26e324860d0023e489 (diff)
downloadlibapr-5f431437bc3ac26739e8fc8b175848baee9c0327.tar.gz
Make ap_snprintf() more robust against border situations with
floating point numbers. Submitted by: Lukas Schroeder <lukas@edeal.de> git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61555 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings')
-rw-r--r--strings/apr_snprintf.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/strings/apr_snprintf.c b/strings/apr_snprintf.c
index 0499531e9..f001a1041 100644
--- a/strings/apr_snprintf.c
+++ b/strings/apr_snprintf.c
@@ -157,7 +157,7 @@ static char *apr_cvt(double arg, int ndigits, int *decpt, int *sign,
*/
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 @@ APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *),
/*
* * 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;