From 6f98eb6488c877a08ef749ae3015858b2fd7c797 Mon Sep 17 00:00:00 2001 From: kevans Date: Wed, 5 Feb 2020 14:00:27 +0000 Subject: [PATCH] wc(1): account for possibility of file == NULL file could reasonably be NULL here if we we're using stdin. Albeit less likely in normal usage, one could actually hit either of these warnings on stdin. ubmitted by: sigsys@gmail.com MFC after: 3 days --- usr.bin/wc/wc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c index 2d3d57df369..a12c13a3e36 100644 --- a/usr.bin/wc/wc.c +++ b/usr.bin/wc/wc.c @@ -246,7 +246,7 @@ cnt(const char *file) */ if (doline == 0 && dolongline == 0) { if (fstat(fd, &sb)) { - xo_warn("%s: fstat", file); + xo_warn("%s: fstat", file != NULL ? file : "stdin"); (void)close(fd); return (1); } @@ -267,7 +267,7 @@ cnt(const char *file) */ while ((len = read(fd, buf, MAXBSIZE))) { if (len == -1) { - xo_warn("%s: read", file); + xo_warn("%s: read", file != NULL ? file : "stdin"); (void)close(fd); return (1); } -- 2.45.0