diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-04 15:31:19 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-04 15:31:19 +0100 |
commit | ded688c6f61c98f1bc1758dc559102c31c919d00 (patch) | |
tree | 59d0d68197c034853d20946c46105f73cb31e308 /coreutils | |
parent | 692bcff577fd3844e2017ffa6864d56f7a2bb5ad (diff) | |
download | busybox-w32-ded688c6f61c98f1bc1758dc559102c31c919d00.tar.gz busybox-w32-ded688c6f61c98f1bc1758dc559102c31c919d00.tar.bz2 busybox-w32-ded688c6f61c98f1bc1758dc559102c31c919d00.zip |
fold: fix a corner case. By Tomas Heinrich (heinrich.tomas AT gmail.com)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/fold.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/coreutils/fold.c b/coreutils/fold.c index e2a30d5d4..56a346680 100644 --- a/coreutils/fold.c +++ b/coreutils/fold.c | |||
@@ -30,7 +30,7 @@ static int adjust_column(int column, char c) | |||
30 | column = 0; | 30 | column = 0; |
31 | else if (c == '\t') | 31 | else if (c == '\t') |
32 | column = column + 8 - column % 8; | 32 | column = column + 8 - column % 8; |
33 | else /* if (isprint (c)) */ | 33 | else /* if (isprint(c)) */ |
34 | column++; | 34 | column++; |
35 | } else | 35 | } else |
36 | column++; | 36 | column++; |
@@ -38,7 +38,7 @@ static int adjust_column(int column, char c) | |||
38 | } | 38 | } |
39 | 39 | ||
40 | int fold_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 40 | int fold_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
41 | int fold_main(int argc, char **argv) | 41 | int fold_main(int argc UNUSED_PARAM, char **argv) |
42 | { | 42 | { |
43 | char *line_out = NULL; | 43 | char *line_out = NULL; |
44 | int allocated_out = 0; | 44 | int allocated_out = 0; |
@@ -49,7 +49,7 @@ int fold_main(int argc, char **argv) | |||
49 | 49 | ||
50 | if (ENABLE_INCLUDE_SUSv2) { | 50 | if (ENABLE_INCLUDE_SUSv2) { |
51 | /* Turn any numeric options into -w options. */ | 51 | /* Turn any numeric options into -w options. */ |
52 | for (i = 1; i < argc; i++) { | 52 | for (i = 1; argv[i]; i++) { |
53 | char const *a = argv[i]; | 53 | char const *a = argv[i]; |
54 | 54 | ||
55 | if (*a++ == '-') { | 55 | if (*a++ == '-') { |
@@ -122,11 +122,10 @@ int fold_main(int argc, char **argv) | |||
122 | } | 122 | } |
123 | goto rescan; | 123 | goto rescan; |
124 | } | 124 | } |
125 | } else { | 125 | } |
126 | if (offset_out == 0) { | 126 | if (offset_out == 0) { |
127 | line_out[offset_out++] = c; | 127 | line_out[offset_out++] = c; |
128 | continue; | 128 | continue; |
129 | } | ||
130 | } | 129 | } |
131 | line_out[offset_out++] = '\n'; | 130 | line_out[offset_out++] = '\n'; |
132 | fwrite(line_out, sizeof(char), (size_t) offset_out, stdout); | 131 | fwrite(line_out, sizeof(char), (size_t) offset_out, stdout); |