summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorMatt Kraai2001-05-05 16:19:13 +0000
committerMatt Kraai2001-05-05 16:19:13 +0000
commit2e6c87876353cf5e038d8430c076f645be51da75 (patch)
tree0884fd34c92feae004fa616b323366ab97d3a24e /coreutils
parent6b8c550d88e87c46bd8b168920492b54bdc9dc9f (diff)
downloadbusybox-2e6c87876353cf5e038d8430c076f645be51da75.zip
busybox-2e6c87876353cf5e038d8430c076f645be51da75.tar.gz
Rewrite -c and -b processing to shrink code and eliminate buffer overrun.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cut.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c
index d852ab3..efcb325 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -108,20 +108,10 @@ static void cut_file(FILE *file)
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
/* cut based on chars/bytes */
if (part == 'c' || part == 'b') {
- int i;
- /* a valid end position has been specified */
- if (endpos > 0) {
- for (i = startpos-1; i < endpos; i++) {
- fputc(line[i], stdout);
- }
- fputc('\n', stdout);
- }
- /* otherwise, just go to the end of the line */
- else {
- for (i = startpos-1; line[i]; i++) {
- fputc(line[i], stdout);
- }
- }
+ chomp(line);
+ if (0 < endpos && endpos < strlen(line))
+ line[endpos] = '\0';
+ puts(line + startpos - 1);
}
/* cut based on fields */
else if (part == 'f') {