diff options
author | Matt Kraai <kraai@debian.org> | 2001-05-05 16:19:13 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-05-05 16:19:13 +0000 |
commit | 2e6c87876353cf5e038d8430c076f645be51da75 (patch) | |
tree | 0884fd34c92feae004fa616b323366ab97d3a24e | |
parent | 6b8c550d88e87c46bd8b168920492b54bdc9dc9f (diff) | |
download | busybox-w32-2e6c87876353cf5e038d8430c076f645be51da75.tar.gz busybox-w32-2e6c87876353cf5e038d8430c076f645be51da75.tar.bz2 busybox-w32-2e6c87876353cf5e038d8430c076f645be51da75.zip |
Rewrite -c and -b processing to shrink code and eliminate buffer overrun.
-rw-r--r-- | coreutils/cut.c | 18 | ||||
-rw-r--r-- | cut.c | 18 |
2 files changed, 8 insertions, 28 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index d852ab3be..efcb325df 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -108,20 +108,10 @@ static void cut_file(FILE *file) | |||
108 | for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) { | 108 | for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) { |
109 | /* cut based on chars/bytes */ | 109 | /* cut based on chars/bytes */ |
110 | if (part == 'c' || part == 'b') { | 110 | if (part == 'c' || part == 'b') { |
111 | int i; | 111 | chomp(line); |
112 | /* a valid end position has been specified */ | 112 | if (0 < endpos && endpos < strlen(line)) |
113 | if (endpos > 0) { | 113 | line[endpos] = '\0'; |
114 | for (i = startpos-1; i < endpos; i++) { | 114 | puts(line + startpos - 1); |
115 | fputc(line[i], stdout); | ||
116 | } | ||
117 | fputc('\n', stdout); | ||
118 | } | ||
119 | /* otherwise, just go to the end of the line */ | ||
120 | else { | ||
121 | for (i = startpos-1; line[i]; i++) { | ||
122 | fputc(line[i], stdout); | ||
123 | } | ||
124 | } | ||
125 | } | 115 | } |
126 | /* cut based on fields */ | 116 | /* cut based on fields */ |
127 | else if (part == 'f') { | 117 | else if (part == 'f') { |
@@ -108,20 +108,10 @@ static void cut_file(FILE *file) | |||
108 | for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) { | 108 | for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) { |
109 | /* cut based on chars/bytes */ | 109 | /* cut based on chars/bytes */ |
110 | if (part == 'c' || part == 'b') { | 110 | if (part == 'c' || part == 'b') { |
111 | int i; | 111 | chomp(line); |
112 | /* a valid end position has been specified */ | 112 | if (0 < endpos && endpos < strlen(line)) |
113 | if (endpos > 0) { | 113 | line[endpos] = '\0'; |
114 | for (i = startpos-1; i < endpos; i++) { | 114 | puts(line + startpos - 1); |
115 | fputc(line[i], stdout); | ||
116 | } | ||
117 | fputc('\n', stdout); | ||
118 | } | ||
119 | /* otherwise, just go to the end of the line */ | ||
120 | else { | ||
121 | for (i = startpos-1; line[i]; i++) { | ||
122 | fputc(line[i], stdout); | ||
123 | } | ||
124 | } | ||
125 | } | 115 | } |
126 | /* cut based on fields */ | 116 | /* cut based on fields */ |
127 | else if (part == 'f') { | 117 | else if (part == 'f') { |