From b7c354e27c05bf11e63e310dfed8029ecfe065d8 Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 22 Apr 1999 23:40:56 +0000 Subject: fix -n with 16-chars hostnames, modified patch from PR PR: 11286 Submitted by: Hans Huebner --- usr.bin/w/w.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'usr.bin/w/w.c') diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 26a6040..9e1fe70 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94"; #endif static const char rcsid[] = - "$Id: w.c,v 1.32 1999/01/10 15:28:37 peter Exp $"; + "$Id: w.c,v 1.33 1999/03/31 21:01:39 brian Exp $"; #endif /* not lint */ /* @@ -335,7 +335,11 @@ main(argc, argv) } for (ep = ehead; ep != NULL; ep = ep->next) { - p = *ep->utmp.ut_host ? ep->utmp.ut_host : "-"; + char host_buf[UT_HOSTSIZE + 1]; + + host_buf[UT_HOSTSIZE] = '\0'; + strncpy(host_buf, ep->utmp.ut_host, UT_HOSTSIZE); + p = *host_buf ? host_buf : "-"; if ((x = strchr(p, ':')) != NULL) *x++ = '\0'; if (!nflag && isdigit(*p) && @@ -362,8 +366,7 @@ main(argc, argv) } } if (x) { - (void)snprintf(buf, sizeof(buf), "%s:%.*s", p, - ep->utmp.ut_host + UT_HOSTSIZE - x, x); + (void)snprintf(buf, sizeof(buf), "%s:%s", p, x); p = buf; } if (dflag) { -- cgit v1.1