From 0b3d6b68f7ee25f92afff8a1a43938476e2a1cc1 Mon Sep 17 00:00:00 2001 From: "wtc%google.com" Date: Sat, 11 Oct 2008 16:24:34 +0000 Subject: [PATCH] Bug 455556: output an empty string when PR_FormatTime fails. The patch is contributed by Julien Pierre . r=wtc. git-svn-id: svn://10.0.0.236/trunk@254599 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/nsprpub/pr/src/misc/prtime.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mozilla/nsprpub/pr/src/misc/prtime.c b/mozilla/nsprpub/pr/src/misc/prtime.c index 3ac27afa488..d73b08cdeae 100644 --- a/mozilla/nsprpub/pr/src/misc/prtime.c +++ b/mozilla/nsprpub/pr/src/misc/prtime.c @@ -1696,6 +1696,7 @@ PR_ParseTimeString( PR_IMPLEMENT(PRUint32) PR_FormatTime(char *buf, int buflen, const char *fmt, const PRExplodedTime *tm) { + size_t rv; struct tm a; a.tm_sec = tm->tm_sec; a.tm_min = tm->tm_min; @@ -1719,7 +1720,16 @@ PR_FormatTime(char *buf, int buflen, const char *fmt, const PRExplodedTime *tm) a.tm_gmtoff = tm->tm_params.tp_gmt_offset + tm->tm_params.tp_dst_offset; #endif - return strftime(buf, buflen, fmt, &a); + rv = strftime(buf, buflen, fmt, &a); + if (!rv && buf && buflen > 0) { + /* + * When strftime fails, the contents of buf are indeterminate. + * Some callers don't check the return value from this function, + * so store an empty string in buf in case they try to print it. + */ + buf[0] = '\0'; + } + return rv; }