summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2023-04-23 23:45:08 +0100
committerPádraig Brady <P@draigBrady.com>2023-04-24 11:46:28 +0100
commit82e1750daa3d002717234d8b37d21bdefbf826f4 (patch)
treee2c06d6ad4354cdbaee7fe9d6d88e9e3cf79ccfb
parent5595673d5cc2e3939edb898823dfb069296aa5b2 (diff)
downloadcoreutils-82e1750daa3d002717234d8b37d21bdefbf826f4.tar.gz
factor: diagnose errors reading the input
* src/factor.c (do_stdin): Exit with failure upon read errors. * NEWS: Mention the bug fix.
-rw-r--r--NEWS2
-rw-r--r--src/factor.c7
2 files changed, 7 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index ec4920edc..0590dd13a 100644
--- a/NEWS
+++ b/NEWS
@@ -11,7 +11,7 @@ GNU coreutils NEWS -*- outline -*-
Previously such file names would have caused the strip process to fail.
[This bug was present in "the beginning".]
- tsort and numfmt now diagnose read errors on the input.
+ factor, numfmt, and tsort now diagnose read errors on the input.
[This bug was present in "the beginning".]
diff --git a/src/factor.c b/src/factor.c
index 20508e355..d37058bbe 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -2588,7 +2588,12 @@ do_stdin (void)
size_t token_length = readtoken (stdin, DELIM, sizeof (DELIM) - 1,
&tokenbuffer);
if (token_length == (size_t) -1)
- break;
+ {
+ if (ferror (stdin))
+ die (EXIT_FAILURE, errno, _("error reading input"));
+ break;
+ }
+
ok &= print_factors (tokenbuffer.buffer);
}
free (tokenbuffer.buffer);