aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index bf42753c5..f166aa48a 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -629,30 +629,33 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
629 629
630 /* do normal option parsing */ 630 /* do normal option parsing */
631#if ENABLE_FEATURE_GREP_CONTEXT 631#if ENABLE_FEATURE_GREP_CONTEXT
632 int Copt; 632 int Copt, opts;
633 633
634 /* -H unsets -h; -C unsets -A,-B; -e,-f are lists; 634 /* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
635 * -m,-A,-B,-C have numeric param */ 635 * -m,-A,-B,-C have numeric param */
636 opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+"; 636 opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+";
637 getopt32(argv, 637 opts = getopt32(argv,
638 OPTSTR_GREP, 638 OPTSTR_GREP,
639 &pattern_head, &fopt, &max_matches, 639 &pattern_head, &fopt, &max_matches,
640 &lines_after, &lines_before, &Copt); 640 &lines_after, &lines_before, &Copt);
641 641
642 if (option_mask32 & OPT_C) { 642 if (opts & OPT_C) {
643 /* -C unsets prev -A and -B, but following -A or -B 643 /* -C unsets prev -A and -B, but following -A or -B
644 may override it */ 644 may override it */
645 if (!(option_mask32 & OPT_A)) /* not overridden */ 645 if (!(opts & OPT_A)) /* not overridden */
646 lines_after = Copt; 646 lines_after = Copt;
647 if (!(option_mask32 & OPT_B)) /* not overridden */ 647 if (!(opts & OPT_B)) /* not overridden */
648 lines_before = Copt; 648 lines_before = Copt;
649 } 649 }
650 /* sanity checks */ 650 /* sanity checks */
651 if (option_mask32 & (OPT_c|OPT_q|OPT_l|OPT_L)) { 651 if (opts & (OPT_c|OPT_q|OPT_l|OPT_L)) {
652 option_mask32 &= ~OPT_n; 652 option_mask32 &= ~OPT_n;
653 lines_before = 0; 653 lines_before = 0;
654 lines_after = 0; 654 lines_after = 0;
655 } else if (lines_before > 0) { 655 } else if (lines_before > 0) {
656 if (lines_before > INT_MAX / sizeof(long long))
657 lines_before = INT_MAX / sizeof(long long);
658 /* overflow in (lines_before * sizeof(x)) is prevented (above) */
656 before_buf = xzalloc(lines_before * sizeof(before_buf[0])); 659 before_buf = xzalloc(lines_before * sizeof(before_buf[0]));
657 IF_EXTRA_COMPAT(before_buf_size = xzalloc(lines_before * sizeof(before_buf_size[0]));) 660 IF_EXTRA_COMPAT(before_buf_size = xzalloc(lines_before * sizeof(before_buf_size[0]));)
658 } 661 }