Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: nspr/pr/src/io/prprf.c

Issue 407383002: Update to NSPR 4.10.7 Beta 3. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/nss
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « nspr/pr/src/io/prmapopt.c ('k') | nspr/pr/src/md/windows/w95io.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: nspr/pr/src/io/prprf.c
diff --git a/nspr/pr/src/io/prprf.c b/nspr/pr/src/io/prprf.c
index aa7852ffad12b3732e8919ead7feebbeeb5f93f4..a2eb4171a846aaf5a39a06ff0a2feddafdfab169 100644
--- a/nspr/pr/src/io/prprf.c
+++ b/nspr/pr/src/io/prprf.c
@@ -18,6 +18,10 @@
#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)
*/
@@ -304,7 +308,7 @@ static int cvt_ll(SprintfState *ss, PRInt64 num, int width, int prec, int radix,
** 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)
{
@@ -312,15 +316,14 @@ static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
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;
@@ -330,14 +333,11 @@ static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
}
}
#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));
}
« no previous file with comments | « nspr/pr/src/io/prmapopt.c ('k') | nspr/pr/src/md/windows/w95io.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698