summaryrefslogtreecommitdiff
path: root/src/sum.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-10-27 13:13:59 +0000
committerPádraig Brady <P@draigBrady.com>2015-10-27 17:24:54 +0000
commit6796698c9945d87236ffcc939137d0919ef04931 (patch)
treedd843e7808186887c2959451e34fdd7f42783359 /src/sum.c
parent106d4bf159a97b573d6479473fa38216fb8bfada (diff)
downloadcoreutils-6796698c9945d87236ffcc939137d0919ef04931.tar.xz
all: quote string arguments in error messages
These strings are often file names or other user specified parameters, which can give confusing errors in the presence of unexpected characters for example. * cfg.mk (sc_error_quotes): A new syntax check rule. * src/*.c: Wrap error() string arguments with quote(). * tests/: Adjust accordingly. * NEWS: Mention the improvement.
Diffstat (limited to 'src/sum.c')
-rw-r--r--src/sum.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/sum.c b/src/sum.c
index 51956c61f..0c74779cc 100644
--- a/src/sum.c
+++ b/src/sum.c
@@ -27,6 +27,7 @@
#include "error.h"
#include "fadvise.h"
#include "human.h"
+#include "quote.h"
#include "safe-read.h"
#include "xfreopen.h"
@@ -105,7 +106,7 @@ bsd_sum_file (const char *file, int print_name)
fp = fopen (file, (O_BINARY ? "rb" : "r"));
if (fp == NULL)
{
- error (0, errno, "%s", file);
+ error (0, errno, "%s", quote (file));
return false;
}
}
@@ -122,7 +123,7 @@ bsd_sum_file (const char *file, int print_name)
if (ferror (fp))
{
- error (0, errno, "%s", file);
+ error (0, errno, "%s", quote (file));
if (!is_stdin)
fclose (fp);
return false;
@@ -130,7 +131,7 @@ bsd_sum_file (const char *file, int print_name)
if (!is_stdin && fclose (fp) != 0)
{
- error (0, errno, "%s", file);
+ error (0, errno, "%s", quote (file));
return false;
}
@@ -175,7 +176,7 @@ sysv_sum_file (const char *file, int print_name)
fd = open (file, O_RDONLY | O_BINARY);
if (fd == -1)
{
- error (0, errno, "%s", file);
+ error (0, errno, "%s", quote (file));
return false;
}
}
@@ -190,7 +191,7 @@ sysv_sum_file (const char *file, int print_name)
if (bytes_read == SAFE_READ_ERROR)
{
- error (0, errno, "%s", file);
+ error (0, errno, "%s", quote (file));
if (!is_stdin)
close (fd);
return false;
@@ -203,7 +204,7 @@ sysv_sum_file (const char *file, int print_name)
if (!is_stdin && close (fd) != 0)
{
- error (0, errno, "%s", file);
+ error (0, errno, "%s", quote (file));
return false;
}
@@ -270,6 +271,6 @@ main (int argc, char **argv)
ok &= sum_func (argv[optind], files_given);
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, "-");
+ error (EXIT_FAILURE, errno, "%s", quote ("-"));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}