diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | findutils/find.c | 21 | ||||
| -rw-r--r-- | findutils/grep.c | 28 | ||||
| -rw-r--r-- | libbb/lineedit.c | 2 | ||||
| -rw-r--r-- | networking/ntpd.c | 2 | ||||
| -rwxr-xr-x | testsuite/grep.tests | 12 |
6 files changed, 62 insertions, 5 deletions
| @@ -1,6 +1,6 @@ | |||
| 1 | VERSION = 1 | 1 | VERSION = 1 |
| 2 | PATCHLEVEL = 22 | 2 | PATCHLEVEL = 22 |
| 3 | SUBLEVEL = 0 | 3 | SUBLEVEL = 1 |
| 4 | EXTRAVERSION = | 4 | EXTRAVERSION = |
| 5 | NAME = Unnamed | 5 | NAME = Unnamed |
| 6 | 6 | ||
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; | |||
| 1291 | int find_main(int argc UNUSED_PARAM, char **argv) | 1291 | int 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 | } |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index b168f1b86..85643079b 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
| @@ -1255,7 +1255,9 @@ line_input_t* FAST_FUNC new_line_input_t(int flags) | |||
| 1255 | { | 1255 | { |
| 1256 | line_input_t *n = xzalloc(sizeof(*n)); | 1256 | line_input_t *n = xzalloc(sizeof(*n)); |
| 1257 | n->flags = flags; | 1257 | n->flags = flags; |
| 1258 | #if MAX_HISTORY > 0 | ||
| 1258 | n->max_history = MAX_HISTORY; | 1259 | n->max_history = MAX_HISTORY; |
| 1260 | #endif | ||
| 1259 | return n; | 1261 | return n; |
| 1260 | } | 1262 | } |
| 1261 | 1263 | ||
diff --git a/networking/ntpd.c b/networking/ntpd.c index ed83415b4..c4b018778 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
| @@ -1445,6 +1445,8 @@ update_local_clock(peer_t *p) | |||
| 1445 | 1445 | ||
| 1446 | run_script("step", offset); | 1446 | run_script("step", offset); |
| 1447 | 1447 | ||
| 1448 | recv_time += offset; | ||
| 1449 | |||
| 1448 | #if USING_INITIAL_FREQ_ESTIMATION | 1450 | #if USING_INITIAL_FREQ_ESTIMATION |
| 1449 | if (G.discipline_state == STATE_NSET) { | 1451 | if (G.discipline_state == STATE_NSET) { |
| 1450 | set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time); | 1452 | set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time); |
diff --git a/testsuite/grep.tests b/testsuite/grep.tests index 64d99a905..412efffbb 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests | |||
| @@ -147,6 +147,18 @@ testing "grep -w doesn't stop on 1st mismatch" \ | |||
| 147 | "foop foo\n" \ | 147 | "foop foo\n" \ |
| 148 | "" | 148 | "" |
| 149 | 149 | ||
| 150 | testing "grep -w ^str doesn't match str not at the beginning" \ | ||
| 151 | "grep -w ^str input" \ | ||
| 152 | "" \ | ||
| 153 | "strstr\n" \ | ||
| 154 | "" | ||
| 155 | |||
| 156 | testing "grep -w ^ doesn't hang" \ | ||
| 157 | "grep -w ^ input" \ | ||
| 158 | "" \ | ||
| 159 | "anything\n" \ | ||
| 160 | "" | ||
| 161 | |||
| 150 | # testing "test name" "commands" "expected result" "file input" "stdin" | 162 | # testing "test name" "commands" "expected result" "file input" "stdin" |
| 151 | # file input will be file called "input" | 163 | # file input will be file called "input" |
| 152 | # test can create a file "actual" instead of writing to stdout | 164 | # test can create a file "actual" instead of writing to stdout |
