Revert "git-add--interactive: remove hunk coalescing"
[gitweb.git] / grep.c
diff --git a/grep.c b/grep.c
index cace1c8bcb4402f9738ae124b908324b68ff91b3..04c777a20c1a8c10417cc9d44e53e5b99dc32a27 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -72,6 +72,8 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
        struct grep_expr *x;
 
        p = *list;
+       if (!p)
+               return NULL;
        switch (p->token) {
        case GREP_PATTERN: /* atom */
        case GREP_PATTERN_HEAD:
@@ -84,8 +86,6 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
        case GREP_OPEN_PAREN:
                *list = p->next;
                x = compile_pattern_or(list);
-               if (!x)
-                       return NULL;
                if (!*list || (*list)->token != GREP_CLOSE_PAREN)
                        die("unmatched parenthesis");
                *list = (*list)->next;
@@ -101,6 +101,8 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
        struct grep_expr *x;
 
        p = *list;
+       if (!p)
+               return NULL;
        switch (p->token) {
        case GREP_NOT:
                if (!p->next)
@@ -192,7 +194,8 @@ void compile_grep_patterns(struct grep_opt *opt)
         * A classic recursive descent parser would do.
         */
        p = opt->pattern_list;
-       opt->pattern_expression = compile_pattern_expr(&p);
+       if (p)
+               opt->pattern_expression = compile_pattern_expr(&p);
        if (p)
                die("incomplete pattern expression: %s", p->pattern);
 }
@@ -371,6 +374,8 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
        int h = 0;
        regmatch_t match;
 
+       if (!x)
+               die("Not a valid grep expression");
        switch (x->node) {
        case GREP_NODE_ATOM:
                h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);
@@ -490,9 +495,9 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
                *eol = '\0';
                while (next_match(opt, bol, eol, ctx, &match, eflags)) {
                        printf("%.*s%s%.*s%s",
-                              match.rm_so, bol,
+                              (int)match.rm_so, bol,
                               opt->color_match,
-                              match.rm_eo - match.rm_so, bol + match.rm_so,
+                              (int)(match.rm_eo - match.rm_so), bol + match.rm_so,
                               GIT_COLOR_RESET);
                        bol += match.rm_eo;
                        rest -= match.rm_eo;