From 5b9861741563445f079ba5942cec08a6ea040dc4 Mon Sep 17 00:00:00 2001 From: kraai Date: Sat, 5 May 2001 16:19:13 +0000 Subject: 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 --- cut.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'cut.c') diff --git a/cut.c b/cut.c index d852ab3be..efcb325df 100644 --- a/cut.c +++ b/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') { -- cgit v1.2.3-55-g6feb