diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-07-27 22:30:01 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-07-27 22:30:01 +0000 |
commit | 970c414c9386f5e5d419f13819ae037f7cdefa83 (patch) | |
tree | d9e872e56efb1dcacc3d1ed5c112ef02952a7cb2 /usr.sbin/lpr | |
parent | cbca239aab777234ffcec8a3e50d8f2cb0460be7 (diff) |
merge if() and foo = snprintf checks better; millert ok
Diffstat (limited to 'usr.sbin/lpr')
-rw-r--r-- | usr.sbin/lpr/common_source/startdaemon.c | 8 | ||||
-rw-r--r-- | usr.sbin/lpr/lpd/printjob.c | 19 |
2 files changed, 13 insertions, 14 deletions
diff --git a/usr.sbin/lpr/common_source/startdaemon.c b/usr.sbin/lpr/common_source/startdaemon.c index cf4e868cf17..230345a2055 100644 --- a/usr.sbin/lpr/common_source/startdaemon.c +++ b/usr.sbin/lpr/common_source/startdaemon.c @@ -1,4 +1,4 @@ -/* $OpenBSD: startdaemon.c,v 1.8 2002/06/08 01:53:43 millert Exp $ */ +/* $OpenBSD: startdaemon.c,v 1.9 2002/07/27 22:30:00 deraadt Exp $ */ /* $NetBSD: startdaemon.c,v 1.10 1998/07/18 05:04:39 lukem Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)startdaemon.c 8.2 (Berkeley) 4/17/94"; #else -static const char rcsid[] = "$OpenBSD: startdaemon.c,v 1.8 2002/06/08 01:53:43 millert Exp $"; +static const char rcsid[] = "$OpenBSD: startdaemon.c,v 1.9 2002/07/27 22:30:00 deraadt Exp $"; #endif #endif /* not lint */ @@ -96,8 +96,8 @@ startdaemon(char *printer) } PRIV_END; siginterrupt(SIGINT, 0); - n = snprintf(buf, sizeof(buf), "\1%s\n", printer); - if (n >= sizeof(buf) || n == -1) { + if ((n = snprintf(buf, sizeof(buf), "\1%s\n", printer)) >= sizeof(buf) || + n == -1) { close(s); return (0); } diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c index 306eba7dd37..934c0e7e7a8 100644 --- a/usr.sbin/lpr/lpd/printjob.c +++ b/usr.sbin/lpr/lpd/printjob.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printjob.c,v 1.35 2002/06/13 06:48:40 millert Exp $ */ +/* $OpenBSD: printjob.c,v 1.36 2002/07/27 22:30:00 deraadt Exp $ */ /* $NetBSD: printjob.c,v 1.31 2002/01/21 14:42:30 wiz Exp $ */ /* @@ -202,8 +202,8 @@ printjob(void) /* * write process id for others to know */ - pidoff = i = snprintf(line, sizeof(line), "%d\n", pid); - if (pidoff >= sizeof(line)) { + if ((pidoff = i = snprintf(line, sizeof(line), "%d\n", pid)) >= + sizeof(line) || pidoff == -1) { syslog(LOG_ERR, "impossibly large pid: %u", pid); exit(1); } @@ -242,8 +242,8 @@ again: errcnt = 0; restart: (void)lseek(lfd, pidoff, 0); - i = snprintf(line, sizeof(line), "%s\n", q->q_name); - if (i >= sizeof(line)) + if ((i = snprintf(line, sizeof(line), "%s\n", q->q_name)) >= + sizeof(line) || i == -1) i = sizeof(line) - 1; /* can't happen */ if (write(lfd, line, i) != i) syslog(LOG_ERR, "%s: %s: %m", printer, LO); @@ -897,9 +897,8 @@ sendfile(int type, char *file) if (S_ISLNK(stb.st_mode) && fstat(f, &stb) == 0 && (stb.st_dev != fdev || stb.st_ino != fino)) return(ACCESS); - amt = snprintf(buf, sizeof(buf), "%c%lld %s\n", type, - (long long)stb.st_size, file); - if (amt >= sizeof(buf)) + if ((amt = snprintf(buf, sizeof(buf), "%c%lld %s\n", type, + (long long)stb.st_size, file)) >= sizeof(buf) || amt == -1) return (ACCESS); /* XXX hack */ for (i = 0; ; i++) { if (write(pfd, buf, amt) != amt || @@ -1463,8 +1462,8 @@ openrem(void) resp = -1; pfd = getport(RM, 0); if (pfd >= 0) { - n = snprintf(line, sizeof(line), "\2%s\n", RP); - if (n >= sizeof(line)) + if ((n = snprintf(line, sizeof(line), "\2%s\n", RP)) >= + sizeof(line) || n == -1) n = sizeof(line) - 1; if (write(pfd, line, n) == n && (resp = response()) == '\0') |