[git commit master] fold: fix a corner case. By Tomas Heinrich (heinrich.tomas AT gmail.com)

Denys Vlasenko vda.linux at googlemail.com
Wed Nov 4 14:31:19 UTC 2009


commit: http://git.busybox.net/busybox/commit/?id=ded688c6f61c98f1bc1758dc559102c31c919d00
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/fold.c     |   15 +++++++--------
 testsuite/fold.tests |   14 ++++++++++++++
 2 files changed, 21 insertions(+), 8 deletions(-)
 create mode 100755 testsuite/fold.tests

diff --git a/coreutils/fold.c b/coreutils/fold.c
index e2a30d5..56a3466 100644
--- a/coreutils/fold.c
+++ b/coreutils/fold.c
@@ -30,7 +30,7 @@ static int adjust_column(int column, char c)
 			column = 0;
 		else if (c == '\t')
 			column = column + 8 - column % 8;
-		else			/* if (isprint (c)) */
+		else			/* if (isprint(c)) */
 			column++;
 	} else
 		column++;
@@ -38,7 +38,7 @@ static int adjust_column(int column, char c)
 }
 
 int fold_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int fold_main(int argc, char **argv)
+int fold_main(int argc UNUSED_PARAM, char **argv)
 {
 	char *line_out = NULL;
 	int allocated_out = 0;
@@ -49,7 +49,7 @@ int fold_main(int argc, char **argv)
 
 	if (ENABLE_INCLUDE_SUSv2) {
 		/* Turn any numeric options into -w options.  */
-		for (i = 1; i < argc; i++) {
+		for (i = 1; argv[i]; i++) {
 			char const *a = argv[i];
 
 			if (*a++ == '-') {
@@ -122,11 +122,10 @@ int fold_main(int argc, char **argv)
 						}
 						goto rescan;
 					}
-				} else {
-					if (offset_out == 0) {
-						line_out[offset_out++] = c;
-						continue;
-					}
+				}
+				if (offset_out == 0) {
+					line_out[offset_out++] = c;
+					continue;
 				}
 				line_out[offset_out++] = '\n';
 				fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
diff --git a/testsuite/fold.tests b/testsuite/fold.tests
new file mode 100755
index 0000000..5e1f345
--- /dev/null
+++ b/testsuite/fold.tests
@@ -0,0 +1,14 @@
+#!/bin/sh
+# Copyright 2009 by Denys Vlasenko
+# Licensed under GPL v2, see file LICENSE for details.
+
+. testing.sh
+
+# testing "test name" "options" "expected result" "file input" "stdin"
+
+testing "fold -s" "fold -w 7 -s" \
+	"123456\n\t\nasdf" \
+	"" \
+	"123456\tasdf" \
+
+exit $FAILCOUNT
-- 
1.6.3.3



More information about the busybox-cvs mailing list