summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2010-11-10 20:34:52 -0800
committerJim Meyering <meyering@redhat.com>2010-11-11 08:16:24 +0100
commit6568b173db1c98f39a53eadd9b09e0a0e5c11920 (patch)
treeccbc21bc55d866e91db9e97453505d9c66263360 /tests
parent0339eb4598600024cedca14a7e882c1737dd2d82 (diff)
downloadcoreutils-6568b173db1c98f39a53eadd9b09e0a0e5c11920.tar.xz
csplit: do not rely on undefined behavior in printf formats
* doc/coreutils.texi (csplit invocation): Say that %d and %i are aliases for %u. * src/csplit.c (FLAG_THOUSANDS, FLAG_ALTERNATIVE): New constants. (get_format_flags): Now take char const * and int * and return size_t. It now stores info about the flags instead of merely scanning them. Also, it handles '0' correctly. Drop support for the undocumented '+' and ' ' flags since the value is unsigned. Add support for the (undocumented) "'" flag. All uses changed. (get_format_width, get_format_prec): Remove. (check_format_conv_type): Renamed from get_format_conv_type, with a different signature. It now converts the format to one that is compatible with unsigned int, and checks flags. All uses changed. (max_out): Have snprintf compute the number of bytes needed rather than attempting to do it ourselves (which doesn't work portably with outlandish formats such as %4294967296d). (check_format_conv_type, main): Check for overflow in size calculations. Don't assume size_t fits in unsigned int. * tests/misc/csplit: Check for proper handling of flags, with %0#6.3x. Coreutils 8.6 mishandles this somewhat-weird example.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/misc/csplit15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/misc/csplit b/tests/misc/csplit
index bef722485..f365da335 100755
--- a/tests/misc/csplit
+++ b/tests/misc/csplit
@@ -67,6 +67,21 @@ EOF
compare err experr || fail=1
rm -f in out exp err experr
+# `echo | csplit -b '%0#6.3x' - 1' incorrectly warned about the format
+# up through coreutils 8.6.
+echo > in
+csplit -b '%0#6.3x' in 1 > out 2> err || fail=1
+cat <<EOF > exp
+0
+1
+EOF
+compare out exp || fail=1
+touch experr
+compare err experr || fail=1
+compare 'xx 000' experr || fail=1
+compare 'xx 0x001' in || fail=1
+rm -f in out exp err experr xx*
+
# make sure `csplit FILE 0' fails.
echo > in
csplit in 0 > out 2> err && fail=1