aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/cut.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c
index 93b58b493..d81f36bcd 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -143,15 +143,15 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
143 } else if (!opt_REGEX && *delim == '\n') { 143 } else if (!opt_REGEX && *delim == '\n') {
144 unsigned spos = cut_list[cl_pos].startpos; 144 unsigned spos = cut_list[cl_pos].startpos;
145 145
146 linenum++;
146 /* get out if we have no more ranges to process or if the lines 147 /* get out if we have no more ranges to process or if the lines
147 * are lower than what we're interested in */ 148 * are lower than what we're interested in */
148 if ((linenum < spos) || END_OF_LIST(cut_list[cl_pos])) 149 if (linenum <= spos || END_OF_LIST(cut_list[cl_pos]))
149 goto next_line; 150 goto next_line;
150 151
151 /* if the line we're looking for is lower than the one we were 152 /* if the line we're looking for is lower than the one we were
152 * passed, it means we displayed it already, so move on */ 153 * passed, it means we displayed it already, so move on */
153 while (spos < linenum) { 154 while (++spos < linenum) {
154 spos++;
155 /* go to the next list if we're at the end of this one */ 155 /* go to the next list if we're at the end of this one */
156 if (spos > cut_list[cl_pos].endpos) { 156 if (spos > cut_list[cl_pos].endpos) {
157 cl_pos++; 157 cl_pos++;
@@ -161,7 +161,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
161 spos = cut_list[cl_pos].startpos; 161 spos = cut_list[cl_pos].startpos;
162 /* get out if the current line is lower than the one 162 /* get out if the current line is lower than the one
163 * we just became interested in */ 163 * we just became interested in */
164 if (linenum < spos) 164 if (linenum <= spos)
165 goto next_line; 165 goto next_line;
166 } 166 }
167 } 167 }
@@ -280,7 +280,6 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
280 /* if we printed anything, finish with newline */ 280 /* if we printed anything, finish with newline */
281 putchar('\n'); 281 putchar('\n');
282 next_line: 282 next_line:
283 linenum++;
284 free(line); 283 free(line);
285 } /* while (got line) */ 284 } /* while (got line) */
286 285
@@ -399,7 +398,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
399 //if (nranges == 0) 398 //if (nranges == 0)
400 // bb_simple_error_msg_and_die("missing list of positions"); 399 // bb_simple_error_msg_and_die("missing list of positions");
401 //^^^ this is impossible since one of -bcfF is required, 400 //^^^ this is impossible since one of -bcfF is required,
402 // they populate LIST with non-empty string and when it is parsed, 401 // they populate LIST with non-NULL string and when it is parsed,
403 // cut_list[] gets at least one element. 402 // cut_list[] gets at least one element.
404 403
405 /* now that the lists are parsed, we need to sort them to make life 404 /* now that the lists are parsed, we need to sort them to make life