diff options
author | kraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-05-05 16:19:13 +0000 |
---|---|---|
committer | kraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-05-05 16:19:13 +0000 |
commit | 5b9861741563445f079ba5942cec08a6ea040dc4 (patch) | |
tree | 0884fd34c92feae004fa616b323366ab97d3a24e /cut.c | |
parent | 1c9762a336626ec69fb65c95658776f935033d43 (diff) | |
download | busybox-w32-5b9861741563445f079ba5942cec08a6ea040dc4.tar.gz busybox-w32-5b9861741563445f079ba5942cec08a6ea040dc4.tar.bz2 busybox-w32-5b9861741563445f079ba5942cec08a6ea040dc4.zip |
Rewrite -c and -b processing to shrink code and eliminate buffer overrun.
git-svn-id: svn://busybox.net/trunk/busybox@2543 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'cut.c')
-rw-r--r-- | cut.c | 18 |
1 files changed, 4 insertions, 14 deletions
@@ -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') { |