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
This commit is contained in:
Kyle Evans
2020-02-05 14:00:27 +00:00
parent 380977d557
commit fbdf47586e
+2 -2
View File
@@ -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);
}