aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-01-20 03:41:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-01-20 03:41:48 +0100
commitd9e0c438e10e2155513e5d26498af472c5137d65 (patch)
tree2c53de479f949ab21f9fa9227e31e01e1aba7b27 /findutils
parenta2dd4ee0e80f50e204f4755e725ae0b1cd07ebad (diff)
downloadbusybox-w32-1_22_1.tar.gz
busybox-w32-1_22_1.tar.bz2
busybox-w32-1_22_1.zip
Apply post-1.22.0 patches, bump version to 1.22.11_22_1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--findutils/find.c21
-rw-r--r--findutils/grep.c28
2 files changed, 45 insertions, 4 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 53d8239c7..5d5e24bfb 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -1291,9 +1291,27 @@ int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1291int find_main(int argc UNUSED_PARAM, char **argv) 1291int find_main(int argc UNUSED_PARAM, char **argv)
1292{ 1292{
1293 int i, firstopt, status = EXIT_SUCCESS; 1293 int i, firstopt, status = EXIT_SUCCESS;
1294 char **past_HLP, *saved;
1294 1295
1295 INIT_G(); 1296 INIT_G();
1296 1297
1298 /* "find -type f" + getopt("+HLP") => disaster.
1299 * Need to avoid getopt running into a non-HLP option.
1300 * Do this by temporarily storing NULL there:
1301 */
1302 past_HLP = argv;
1303 for (;;) {
1304 saved = *++past_HLP;
1305 if (!saved)
1306 break;
1307 if (saved[0] != '-')
1308 break;
1309 if (!saved[1])
1310 break; /* it is "-" */
1311 if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
1312 break;
1313 }
1314 *past_HLP = NULL;
1297 /* "+": stop on first non-option */ 1315 /* "+": stop on first non-option */
1298 i = getopt32(argv, "+HLP"); 1316 i = getopt32(argv, "+HLP");
1299 if (i & (1<<0)) 1317 if (i & (1<<0))
@@ -1301,7 +1319,8 @@ int find_main(int argc UNUSED_PARAM, char **argv)
1301 if (i & (1<<1)) 1319 if (i & (1<<1))
1302 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; 1320 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
1303 /* -P is default and is ignored */ 1321 /* -P is default and is ignored */
1304 argv += optind; 1322 argv = past_HLP; /* same result as "argv += optind;" */
1323 *past_HLP = saved;
1305 1324
1306 for (firstopt = 0; argv[firstopt]; firstopt++) { 1325 for (firstopt = 0; argv[firstopt]; firstopt++) {
1307 if (argv[firstopt][0] == '-') 1326 if (argv[firstopt][0] == '-')
diff --git a/findutils/grep.c b/findutils/grep.c
index b8ad1bf8f..a7bc4ca9e 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -373,6 +373,9 @@ static int grep_file(FILE *file)
373 opt_f_not_found: ; 373 opt_f_not_found: ;
374 } 374 }
375 } else { 375 } else {
376#if ENABLE_EXTRA_COMPAT
377 unsigned start_pos;
378#endif
376 char *match_at; 379 char *match_at;
377 380
378 if (!(gl->flg_mem_alocated_compiled & COMPILED)) { 381 if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
@@ -389,15 +392,18 @@ static int grep_file(FILE *file)
389#if !ENABLE_EXTRA_COMPAT 392#if !ENABLE_EXTRA_COMPAT
390 gl->matched_range.rm_so = 0; 393 gl->matched_range.rm_so = 0;
391 gl->matched_range.rm_eo = 0; 394 gl->matched_range.rm_eo = 0;
395#else
396 start_pos = 0;
392#endif 397#endif
393 match_at = line; 398 match_at = line;
394 opt_w_again: 399 opt_w_again:
400//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
395 if ( 401 if (
396#if !ENABLE_EXTRA_COMPAT 402#if !ENABLE_EXTRA_COMPAT
397 regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0 403 regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
398#else 404#else
399 re_search(&gl->compiled_regex, match_at, line_len, 405 re_search(&gl->compiled_regex, match_at, line_len,
400 /*start:*/ 0, /*range:*/ line_len, 406 start_pos, /*range:*/ line_len,
401 &gl->matched_range) >= 0 407 &gl->matched_range) >= 0
402#endif 408#endif
403 ) { 409 ) {
@@ -416,8 +422,24 @@ static int grep_file(FILE *file)
416 if (!c || (!isalnum(c) && c != '_')) { 422 if (!c || (!isalnum(c) && c != '_')) {
417 found = 1; 423 found = 1;
418 } else { 424 } else {
419 match_at += gl->matched_range.rm_eo; 425 /*
420 goto opt_w_again; 426 * Why check gl->matched_range.rm_eo?
427 * Zero-length match makes -w skip the line:
428 * "echo foo | grep ^" prints "foo",
429 * "echo foo | grep -w ^" prints nothing.
430 * Without such check, we can loop forever.
431 */
432#if !ENABLE_EXTRA_COMPAT
433 if (gl->matched_range.rm_eo != 0) {
434 match_at += gl->matched_range.rm_eo;
435 goto opt_w_again;
436 }
437#else
438 if (gl->matched_range.rm_eo > start_pos) {
439 start_pos = gl->matched_range.rm_eo;
440 goto opt_w_again;
441 }
442#endif
421 } 443 }
422 } 444 }
423 } 445 }