summaryrefslogtreecommitdiff
path: root/src/cksum.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/cksum.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/cksum.c')
-rw-r--r--src/cksum.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cksum.c b/src/cksum.c
index 458827b82..2a19c678a 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -44,6 +44,7 @@
#include <stdint.h>
#include "system.h"
#include "fadvise.h"
+#include "quote.h"
#include "xfreopen.h"
#ifdef CRCTAB
@@ -201,7 +202,7 @@ cksum (const char *file, bool 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;
}
}
@@ -213,7 +214,7 @@ cksum (const char *file, bool print_name)
unsigned char *cp = buf;
if (length + bytes_read < length)
- error (EXIT_FAILURE, 0, _("%s: file too long"), file);
+ error (EXIT_FAILURE, 0, _("%s: file too long"), quote (file));
length += bytes_read;
while (bytes_read--)
crc = (crc << 8) ^ crctab[((crc >> 24) ^ *cp++) & 0xFF];
@@ -223,7 +224,7 @@ cksum (const char *file, bool print_name)
if (ferror (fp))
{
- error (0, errno, "%s", file);
+ error (0, errno, "%s", quote (file));
if (!STREQ (file, "-"))
fclose (fp);
return false;
@@ -231,7 +232,7 @@ cksum (const char *file, bool print_name)
if (!STREQ (file, "-") && fclose (fp) == EOF)
{
- error (0, errno, "%s", file);
+ error (0, errno, "%s", quote (file));
return false;
}