Bug 1018783: Update to NSPR_4_10_6_BETA3.
authorWan-Teh Chang <wtc@google.com>
Wed, 04 Jun 2014 15:14:30 -0700
changeset 205929 90b3655df3b9b78d594fd2b5a41695eeda679a33
parent 205928 d4e390ceac27fe5661e52a42ad9efb48bf148ffc
child 205930 f644eda342c2322de69fddb5a6f47582e03ab6cd
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1018783
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1018783: Update to NSPR_4_10_6_BETA3.
nsprpub/TAG-INFO
nsprpub/config/prdepend.h
nsprpub/pr/src/io/prprf.c
nsprpub/pr/tests/Makefile.in
nsprpub/pr/tests/prfdbl.c
--- a/nsprpub/TAG-INFO
+++ b/nsprpub/TAG-INFO
@@ -1,1 +1,1 @@
-NSPR_4_10_6_BETA2
+NSPR_4_10_6_BETA3
--- a/nsprpub/config/prdepend.h
+++ b/nsprpub/config/prdepend.h
@@ -5,9 +5,8 @@
 
 /*
  * A dummy header file that is a dependency for all the object files.
  * Used to force a full recompilation of NSPR in Mozilla's Tinderbox
  * depend builds.  See comments in rules.mk.
  */
 
 #error "Do not include this header file."
-
--- a/nsprpub/pr/src/io/prprf.c
+++ b/nsprpub/pr/src/io/prprf.c
@@ -13,16 +13,20 @@
 #include <stdio.h>
 #include <string.h>
 #include "primpl.h"
 #include "prprf.h"
 #include "prlong.h"
 #include "prlog.h"
 #include "prmem.h"
 
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
 /*
 ** WARNING: This code may *NOT* call PR_LOG (because PR_LOG calls it)
 */
 
 /*
 ** XXX This needs to be internationalized!
 */
 
@@ -299,50 +303,46 @@ static int cvt_ll(SprintfState *ss, PRIn
     */
     return fill_n(ss, cvt, digits, width, prec, type, flags);
 }
 
 /*
 ** Convert a double precision floating point number into its printable
 ** form.
 **
-** XXX stop using sprintf to convert floating point
+** XXX stop using snprintf to convert floating point
 */
 static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
 {
     char fin[20];
     char fout[300];
     int amount = fmt1 - fmt0;
 
-    PR_ASSERT((amount > 0) && (amount < sizeof(fin)));
-    if (amount >= sizeof(fin)) {
-	/* Totally bogus % command to sprintf. Just ignore it */
+    if (amount <= 0 || amount >= sizeof(fin)) {
+	/* Totally bogus % command to snprintf. Just ignore it */
 	return 0;
     }
     memcpy(fin, fmt0, amount);
     fin[amount] = 0;
 
-    /* Convert floating point using the native sprintf code */
+    /* Convert floating point using the native snprintf code */
 #ifdef DEBUG
     {
         const char *p = fin;
         while (*p) {
             PR_ASSERT(*p != 'L');
             p++;
         }
     }
 #endif
-    sprintf(fout, fin, d);
-
-    /*
-    ** This assert will catch overflow's of fout, when building with
-    ** debugging on. At least this way we can track down the evil piece
-    ** of calling code and fix it!
-    */
-    PR_ASSERT(strlen(fout) < sizeof(fout));
+    memset(fout, 0, sizeof(fout));
+    snprintf(fout, sizeof(fout), fin, d);
+    /* Explicitly null-terminate fout because on Windows snprintf doesn't
+     * append a null-terminator if the buffer is too small. */
+    fout[sizeof(fout) - 1] = '\0';
 
     return (*ss->stuff)(ss, fout, strlen(fout));
 }
 
 /*
 ** Convert a string into its printable form.  "width" is the output
 ** width. "prec" is the maximum number of characters of "s" to output,
 ** where -1 means until NUL.
--- a/nsprpub/pr/tests/Makefile.in
+++ b/nsprpub/pr/tests/Makefile.in
@@ -102,16 +102,17 @@ CSRCS =             \
 	pipeping2.c		\
 	pipepong.c		\
 	pipepong2.c		\
 	pipeself.c		\
 	poll_er.c		\
 	poll_nm.c		\
 	poll_to.c		\
 	pollable.c		\
+	prfdbl.c		\
 	prftest.c		\
 	prftest1.c		\
 	prftest2.c		\
 	primblok.c		\
 	priotest.c		\
 	provider.c		\
 	prpoll.c		\
 	prpollml.c		\
new file mode 100644
--- /dev/null
+++ b/nsprpub/pr/tests/prfdbl.c
@@ -0,0 +1,29 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * This is a simple test of the PR_fprintf() function for doubles.
+ */
+
+#include "prprf.h"
+
+int main()
+{
+    double pi = 3.1415926;
+    double e = 2.71828;
+    double root2 = 1.414;
+    double zero = 0.0;
+    double nan = zero / zero;
+
+    PR_fprintf(PR_STDOUT, "pi is %f.\n", pi);
+    PR_fprintf(PR_STDOUT, "e is %f.\n", e);
+    PR_fprintf(PR_STDOUT, "The square root of 2 is %f.\n", root2);
+    PR_fprintf(PR_STDOUT, "NaN is %f.\n", nan);
+
+    PR_fprintf(PR_STDOUT, "pi is %301f.\n", pi);
+    PR_fprintf(PR_STDOUT, "e is %65416.123f.\n", e);
+    PR_fprintf(PR_STDOUT, "e is %0000000000000000000065416.123f.\n", e);
+    PR_fprintf(PR_STDOUT, "NaN is %1024.1f.\n", nan);
+    return 0;
+}