diff options
author | wtc%google.com <devnull@localhost> | 2008-10-11 16:24:34 +0000 |
---|---|---|
committer | wtc%google.com <devnull@localhost> | 2008-10-11 16:24:34 +0000 |
commit | 1a6bbf827c53cfa5a60604bc43589c73fa7cb14d (patch) | |
tree | d0911b7fa34b0962f2e3d3149d0c5ac0e4211acb | |
parent | 7fbc82f8123385fc8272bd897408db7fd45d7f90 (diff) | |
download | nspr-hg-1a6bbf827c53cfa5a60604bc43589c73fa7cb14d.tar.gz |
Bug 455556: output an empty string when PR_FormatTime fails. The patch isNSPR_4_7_2_BETA4
contributed by Julien Pierre <julien.pierre.boogz@sun.com>. r=wtc.
-rw-r--r-- | pr/src/misc/prtime.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/pr/src/misc/prtime.c b/pr/src/misc/prtime.c index 3ac27afa..d73b08cd 100644 --- a/pr/src/misc/prtime.c +++ b/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; } |