Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/cat Coverity complaint fixes:
details: https://anonhg.NetBSD.org/src/rev/52730cac259c
branches: trunk
changeset: 791814:52730cac259c
user: spz <spz%NetBSD.org@localhost>
date: Tue Dec 03 17:06:51 2013 +0000
description:
Coverity complaint fixes:
bin/cat/cat.c 976654 Argument cannot be negative
(missing check for fileno result, stdout)
bin/cat/cat.c 976653 Improper use of negative value
(missing check for fileno result, stdin)
diffstat:
bin/cat/cat.c | 15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)
diffs (51 lines):
diff -r 1095c823816a -r 52730cac259c bin/cat/cat.c
--- a/bin/cat/cat.c Tue Dec 03 17:01:04 2013 +0000
+++ b/bin/cat/cat.c Tue Dec 03 17:06:51 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cat.c,v 1.52 2012/11/19 19:41:31 christos Exp $ */
+/* $NetBSD: cat.c,v 1.53 2013/12/03 17:06:51 spz Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -44,7 +44,7 @@
#if 0
static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
#else
-__RCSID("$NetBSD: cat.c,v 1.52 2012/11/19 19:41:31 christos Exp $");
+__RCSID("$NetBSD: cat.c,v 1.53 2013/12/03 17:06:51 spz Exp $");
#endif
#endif /* not lint */
@@ -250,9 +250,11 @@
filename = "stdin";
do {
if (*argv) {
- if (!strcmp(*argv, "-"))
+ if (!strcmp(*argv, "-")) {
fd = fileno(stdin);
- else if (fflag) {
+ if (fd < 0)
+ goto skip;
+ } else if (fflag) {
struct stat st;
fd = open(*argv, O_RDONLY|O_NONBLOCK, 0);
if (fd < 0)
@@ -279,7 +281,8 @@
filename = *argv++;
}
raw_cat(fd);
- if (fd != fileno(stdin))
+ /* fd > 0 would be cuter but let's priorize human-readability */
+ if (fd >= 0 && fd != fileno(stdin))
(void)close(fd);
} while (*argv);
}
@@ -294,6 +297,8 @@
int wfd;
wfd = fileno(stdout);
+ if (wfd < 0)
+ err(EXIT_FAILURE, "stdout");
if (buf == NULL) {
struct stat sbuf;
Home |
Main Index |
Thread Index |
Old Index