diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-07-06 18:57:13 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-07-06 18:57:13 +0000 |
commit | 9c1ae051dd38391a967e9c2775b734d7ff9c1147 (patch) | |
tree | 9d896a37636dedac4e298e7dbfe0168b7bafd303 /lib/libc/time | |
parent | 29c9832f6c6b865c809911af28214d7583e332e7 (diff) |
Always NUL terminate buf even if there was not enough space to
write the whole time string. XPG4.2 says
"the contents of the array are indeterminate"
in this case so this is allowed, though obviously you can't rely
on this behavior if you care about portability...
Diffstat (limited to 'lib/libc/time')
-rw-r--r-- | lib/libc/time/strftime.3 | 12 | ||||
-rw-r--r-- | lib/libc/time/strftime.c | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/libc/time/strftime.3 b/lib/libc/time/strftime.3 index 1c33e40f999..136504239a6 100644 --- a/lib/libc/time/strftime.3 +++ b/lib/libc/time/strftime.3 @@ -34,7 +34,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)strftime.3 5.12 (Berkeley) 6/29/91 -.\" $OpenBSD: strftime.3,v 1.4 1998/06/10 17:30:10 deraadt Exp $ +.\" $OpenBSD: strftime.3,v 1.5 1998/07/06 18:57:12 millert Exp $ .\" .Dd Jan 18, 1998 .Dt STRFTIME 3 @@ -204,3 +204,13 @@ and conversion specifications are extensions. .Sh BUGS There is no conversion specification for the phase of the moon. +.Pp +Note that while this implementation of +.Fn strftime +will always NUL terminate +.Fa buf , +other implementations may not do so when +.Fa maxsiz +is not large enough to store the entire time string. The contents of +.Fa buf +are implementation specific in this case. diff --git a/lib/libc/time/strftime.c b/lib/libc/time/strftime.c index 4648331d2ce..2ee6212c854 100644 --- a/lib/libc/time/strftime.c +++ b/lib/libc/time/strftime.c @@ -1,6 +1,6 @@ #if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID) static char elsieid[] = "@(#)strftime.c 7.57"; -static char *rcsid = "$OpenBSD: strftime.c,v 1.2 1998/02/14 21:03:48 millert Exp $"; +static char *rcsid = "$OpenBSD: strftime.c,v 1.3 1998/07/06 18:57:09 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include "private.h" @@ -159,8 +159,10 @@ const struct tm * const t; (void) fprintf(stderr, "\n"); } #endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */ - if (p == s + maxsize) + if (p == s + maxsize) { + s[maxsize - 1] = '\0'; return 0; + } *p = '\0'; return p - s; } |