diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-16 00:19:43 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-16 00:19:43 +0100 |
commit | ba9651b803f0eb2a8cba0205ae72c75ab773adaf (patch) | |
tree | 1e8d8af42423dece63e4425fce7a84efd4ca7f8c | |
parent | e8622f0d8524baf8a08a734b7d0fb6aac31b5ee2 (diff) | |
download | busybox-w32-ba9651b803f0eb2a8cba0205ae72c75ab773adaf.tar.gz busybox-w32-ba9651b803f0eb2a8cba0205ae72c75ab773adaf.tar.bz2 busybox-w32-ba9651b803f0eb2a8cba0205ae72c75ab773adaf.zip |
cut: we can't get empty cut_list[], remove the check for that
function old new delta
.rodata 105685 105659 -26
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/cut.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index 20138075c..3d9f2b373 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -287,7 +287,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv) | |||
287 | /* growable array holding a series of lists */ | 287 | /* growable array holding a series of lists */ |
288 | struct cut_list *cut_list = NULL; | 288 | struct cut_list *cut_list = NULL; |
289 | unsigned nlists = 0; /* number of elements in above list */ | 289 | unsigned nlists = 0; /* number of elements in above list */ |
290 | char *sopt, *ltok; | 290 | char *LIST, *ltok; |
291 | const char *delim = NULL; | 291 | const char *delim = NULL; |
292 | const char *odelim = NULL; | 292 | const char *odelim = NULL; |
293 | unsigned opt; | 293 | unsigned opt; |
@@ -311,7 +311,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv) | |||
311 | "\0" "b:c:f:" IF_FEATURE_CUT_REGEX("F:") /* one of -bcfF is required */ | 311 | "\0" "b:c:f:" IF_FEATURE_CUT_REGEX("F:") /* one of -bcfF is required */ |
312 | "b--"ARG":c--"ARG":f--"ARG IF_FEATURE_CUT_REGEX(":F--"ARG), /* they are mutually exclusive */ | 312 | "b--"ARG":c--"ARG":f--"ARG IF_FEATURE_CUT_REGEX(":F--"ARG), /* they are mutually exclusive */ |
313 | IF_LONG_OPTS(cut_longopts,) | 313 | IF_LONG_OPTS(cut_longopts,) |
314 | &sopt, &sopt, &sopt, &delim, &odelim IF_FEATURE_CUT_REGEX(, &sopt) | 314 | &LIST, &LIST, &LIST, &delim, &odelim IF_FEATURE_CUT_REGEX(, &LIST) |
315 | ); | 315 | ); |
316 | if (!odelim) | 316 | if (!odelim) |
317 | odelim = (opt & OPT_REGEX) ? " " : delim; | 317 | odelim = (opt & OPT_REGEX) ? " " : delim; |
@@ -322,7 +322,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv) | |||
322 | argv += optind; | 322 | argv += optind; |
323 | //if (!(opt & (OPT_BYTE | OPT_CHAR | OPT_FIELDS | OPT_REGEX))) | 323 | //if (!(opt & (OPT_BYTE | OPT_CHAR | OPT_FIELDS | OPT_REGEX))) |
324 | // bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields"); | 324 | // bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields"); |
325 | // ^^^ handled by getopt32 | 325 | //^^^ handled by getopt32 |
326 | 326 | ||
327 | /* non-field (char or byte) cutting has some special handling */ | 327 | /* non-field (char or byte) cutting has some special handling */ |
328 | if (!(opt & (OPT_FIELDS|OPT_REGEX))) { | 328 | if (!(opt & (OPT_FIELDS|OPT_REGEX))) { |
@@ -344,7 +344,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv) | |||
344 | * more than one range can be separated by commas | 344 | * more than one range can be separated by commas |
345 | */ | 345 | */ |
346 | /* take apart the ranges, one by one (separated with commas) */ | 346 | /* take apart the ranges, one by one (separated with commas) */ |
347 | while ((ltok = strsep(&sopt, ",")) != NULL) { | 347 | while ((ltok = strsep(&LIST, ",")) != NULL) { |
348 | char *ntok; | 348 | char *ntok; |
349 | int s, e; | 349 | int s, e; |
350 | 350 | ||
@@ -382,17 +382,20 @@ int cut_main(int argc UNUSED_PARAM, char **argv) | |||
382 | if (s < 0 || e < s) | 382 | if (s < 0 || e < s) |
383 | bb_error_msg_and_die("invalid range %s-%s", ntok, ltok ?: ntok); | 383 | bb_error_msg_and_die("invalid range %s-%s", ntok, ltok ?: ntok); |
384 | 384 | ||
385 | /* add the new list */ | 385 | /* add the new range */ |
386 | cut_list = xrealloc_vector(cut_list, 4, nlists); | 386 | cut_list = xrealloc_vector(cut_list, 4, nlists); |
387 | /* NB: startpos is always >= 0 */ | 387 | /* NB: s is always >= 0 */ |
388 | cut_list[nlists].startpos = s; | 388 | cut_list[nlists].startpos = s; |
389 | cut_list[nlists].endpos = e; | 389 | cut_list[nlists].endpos = e; |
390 | nlists++; | 390 | nlists++; |
391 | } | 391 | } |
392 | 392 | ||
393 | /* make sure we got some cut positions out of all that */ | 393 | /* make sure we got some cut positions out of all that */ |
394 | if (nlists == 0) | 394 | //if (nlists == 0) |
395 | bb_simple_error_msg_and_die("missing list of positions"); | 395 | // bb_simple_error_msg_and_die("missing list of positions"); |
396 | //^^^ this is impossible since one of -bcfF is required, | ||
397 | // they populate LIST with non-empty string and when it is parsed, | ||
398 | // cut_list[] gets at least one element. | ||
396 | 399 | ||
397 | /* now that the lists are parsed, we need to sort them to make life | 400 | /* now that the lists are parsed, we need to sort them to make life |
398 | * easier on us when it comes time to print the chars / fields / lines | 401 | * easier on us when it comes time to print the chars / fields / lines |