summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2016-11-04 16:55:58 +0000
committerPádraig Brady <P@draigBrady.com>2016-11-04 20:38:32 +0000
commitc6656eed6ae9536812012a1b0d0b31ec960acf23 (patch)
treef2cbda8c7150d028de4cb2ccdacec58c82919888
parentd0ddfadfb27def2861f35b1a45190a4c1780b257 (diff)
downloadcoreutils-c6656eed6ae9536812012a1b0d0b31ec960acf23.tar.xz
dd: warn about counts specified with confusing 0x prefix
* src/dd.c (parse_integer): Suggest to use "00x" instead of "0x", which is significant for the "count", "seek", and "skip" operands. * tests/dd/misc.sh: Add a test case. Fixes http://bugs.gnu.org/24874
-rw-r--r--src/dd.c6
-rwxr-xr-xtests/dd/misc.sh10
2 files changed, 16 insertions, 0 deletions
diff --git a/src/dd.c b/src/dd.c
index 2c6d4c6ab..c7f54d4b4 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1342,6 +1342,12 @@ parse_integer (const char *str, strtol_error *invalid)
return 0;
}
+ if (n == 0 && STRPREFIX (str, "0x"))
+ error (0, 0,
+ _("warning: %s is a zero multiplier; "
+ "use %s if that is intended"),
+ quote_n (0, "0x"), quote_n (1, "00x"));
+
n *= multiplier;
}
else if (e != LONGINT_OK)
diff --git a/tests/dd/misc.sh b/tests/dd/misc.sh
index 2c24b5087..094fc5375 100755
--- a/tests/dd/misc.sh
+++ b/tests/dd/misc.sh
@@ -107,4 +107,14 @@ compare err_ok err || fail=1
test $fail -eq 0 && fail=$warn
+# Check a warning is issued for ambiguous 0x... numbers
+dd if=/dev/null count=0x1 seek=0x1 skip=0x1 status=none 2>err || fail=1
+cat <<\EOF >exp
+dd: warning: '0x' is a zero multiplier; use '00x' if that is intended
+dd: warning: '0x' is a zero multiplier; use '00x' if that is intended
+dd: warning: '0x' is a zero multiplier; use '00x' if that is intended
+EOF
+compare exp err || fail=1
+
+
Exit $fail