Use strlcpy/strlcat instead of strn* plus manual termination.

Use sizeof() instead of hardcoded length. Clean up NULL vs 0
confusion. sizeof(char) is 1, really.
This commit is contained in:
mjl 2000-09-19 16:17:48 +00:00
parent 300fe58019
commit 4fdc259981
2 changed files with 11 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.31 2000/01/14 02:10:08 ad Exp $ */
/* $NetBSD: main.c,v 1.32 2000/09/19 16:17:48 mjl Exp $ */
/*-
* Copyright (c) 1980, 1993
@ -44,7 +44,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0
static char sccsid[] = "from: @(#)main.c 8.1 (Berkeley) 6/20/93";
#else
__RCSID("$NetBSD: main.c,v 1.31 2000/01/14 02:10:08 ad Exp $");
__RCSID("$NetBSD: main.c,v 1.32 2000/09/19 16:17:48 mjl Exp $");
#endif
#endif /* not lint */
@ -238,19 +238,18 @@ main(argc, argv)
* J. Gettys - MIT Project Athena.
*/
if (argc <= 2 || strcmp(argv[2], "-") == 0) {
strncpy(ttyn, ttyname(0), 32);
ttyn[31] = (char)NULL;
strlcpy(ttyn, ttyname(0), sizeof(ttyn));
}
else {
int i;
strcpy(ttyn, dev);
strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
strlcpy(ttyn, dev, sizeof(ttyn));
strlcat(ttyn, argv[2], sizeof(ttyn));
if (uugetty) {
chown(ttyn, ttyowner, 0);
strcpy(lockfile, _PATH_LOCK);
strncat(lockfile, argv[2], sizeof(lockfile)-sizeof(_PATH_LOCK));
strlcat(lockfile, argv[2], sizeof(lockfile));
/* wait for lockfiles to go away before we try to open */
if ( pidlock(lockfile, 0, 0, 0) != 0 ) {
syslog(LOG_ERR, "%s: can't create lockfile", ttyn);
@ -651,7 +650,7 @@ putf(cp)
case 't':
slash = strrchr(ttyn, '/');
if (slash == (char *) 0)
if (slash == NULL)
xputs(ttyn);
else
xputs(&slash[1]);

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr.c,v 1.23 1998/03/30 01:52:02 mrg Exp $ */
/* $NetBSD: subr.c,v 1.24 2000/09/19 16:17:48 mjl Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)subr.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: subr.c,v 1.23 1998/03/30 01:52:02 mrg Exp $");
__RCSID("$NetBSD: subr.c,v 1.24 2000/09/19 16:17:48 mjl Exp $");
#endif
#endif /* not lint */
@ -612,8 +612,7 @@ makeenv(env)
ep = env;
if (TT && *TT) {
strncat(termbuf, TT, 128);
termbuf[127] = (char)NULL;
strlcat(termbuf, TT, sizeof(termbuf));
*ep++ = termbuf;
}
if ((p = EV) != NULL) {
@ -701,7 +700,7 @@ autobaud()
if (select(32, (fd_set *)&rfds, (fd_set *)NULL,
(fd_set *)NULL, &timeout) <= 0)
return (type);
if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char))
if (read(STDIN_FILENO, &c, 1) != 1)
return (type);
timeout.tv_sec = 0;
timeout.tv_usec = 20;