summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%google.com <devnull@localhost>2009-11-14 19:58:46 +0000
committerwtc%google.com <devnull@localhost>2009-11-14 19:58:46 +0000
commit73c0a71cca46a8db789343976dda592a97723fd3 (patch)
tree515bf91aa6e49514875eac9e56cea7dd427e1354
parente6217e491c4673de4fb1dcd5899f0df2d979f358 (diff)
downloadnspr-hg-73c0a71cca46a8db789343976dda592a97723fd3.tar.gz
Bug 521306: Add a test case with a very long input for PR_strtod. r=reed.NSPR_HEAD_20091118NSPR_4_8_3_BETA
-rw-r--r--pr/tests/dtoa.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/pr/tests/dtoa.c b/pr/tests/dtoa.c
index e021ffa0..f4939ac8 100644
--- a/pr/tests/dtoa.c
+++ b/pr/tests/dtoa.c
@@ -47,6 +47,7 @@
*
*****************************************************************************/
#include <stdio.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <locale.h>
@@ -61,6 +62,7 @@ int main(int argc, char **argv)
double num1;
double zero = 0.0;
char cnvt[50];
+ char *thousands;
num = 1e24;
num1 = PR_strtod("1e24",NULL);
@@ -195,7 +197,6 @@ int main(int argc, char **argv)
failed_already = 1;
}
-
num = -1.0000000001e-21;
num1 = PR_strtod("-1.0000000001e-21",NULL);
if(num1 != num){
@@ -215,6 +216,26 @@ int main(int argc, char **argv)
*/
num1 = PR_strtod("4e-356",NULL);
+ /*
+ * A very long input with ~384K digits.
+ * Bug 516396: Should not crash.
+ * Bug 521306: Should return 0 without converting the input.
+ */
+#define LENGTH (384 * 1024)
+ thousands = (char *)malloc(LENGTH);
+ thousands[0] = '0';
+ thousands[1] = '.';
+ memset(&thousands[2], '1', LENGTH - 3);
+ thousands[LENGTH - 1] = '\0';
+ num = 0;
+ num1 = PR_strtod(thousands,NULL);
+ free(thousands);
+ if(num1 != num){
+ fprintf(stderr,"Failed to convert numeric value %s\n",
+ "0.1111111111111111...");
+ failed_already = 1;
+ }
+
if (failed_already) {
printf("FAILED\n");
} else {