From 69fe77ce99d22158d0d9c6f7dd69faffb049b8d0 Mon Sep 17 00:00:00 2001 From: Philippe Charnier Date: Sun, 7 Sep 2003 16:31:32 +0000 Subject: Do not print the result of strftime() in case of failure, the content is indeterminate in such a case. The correct value for 2nd argument is sizeof(buf). Do not NUL-terminate the result string, strftime() will do it for us. --- usr.bin/w/w.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 8bf63d1573882..ebf2a87096d47 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -432,11 +432,9 @@ pr_header(time_t *nowp, int nusers) /* * Print time of day. */ - (void)strftime(buf, sizeof(buf) - 1, - use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)); - buf[sizeof(buf) - 1] = '\0'; - (void)printf("%s ", buf); - + if (strftime(buf, sizeof(buf), + use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)) != 0) + (void)printf("%s ", buf); /* * Print how long system has been up. * (Found by looking getting "boottime" from the kernel) -- cgit v1.3