]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-grep.c
Merge branch 'maint'
[git.git] / builtin-grep.c
index 185876b0a6dc191bb5adc22cd5c2f012cd70e479..f1ff8dc556ce6caa1cafe77be41396dd9b7c9ee6 100644 (file)
@@ -294,7 +294,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
                        if (opt->pre_context) {
                                push_arg("-B");
                                len += snprintf(argptr, sizeof(randarg)-len,
-                                               "%u", opt->pre_context);
+                                               "%u", opt->pre_context) + 1;
                                if (sizeof(randarg) <= len)
                                        die("maximum length of args exceeded");
                                push_arg(argptr);
@@ -303,7 +303,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
                        if (opt->post_context) {
                                push_arg("-A");
                                len += snprintf(argptr, sizeof(randarg)-len,
-                                               "%u", opt->post_context);
+                                               "%u", opt->post_context) + 1;
                                if (sizeof(randarg) <= len)
                                        die("maximum length of args exceeded");
                                push_arg(argptr);
@@ -313,7 +313,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
                else {
                        push_arg("-C");
                        len += snprintf(argptr, sizeof(randarg)-len,
-                                       "%u", opt->post_context);
+                                       "%u", opt->post_context) + 1;
                        if (sizeof(randarg) <= len)
                                die("maximum length of args exceeded");
                        push_arg(argptr);
@@ -343,12 +343,12 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
                        memcpy(name + 2, ce->name, len + 1);
                }
                argv[argc++] = name;
-               if (argc < MAXARGS)
-                       continue;
-               status = flush_grep(opt, argc, nr, argv, &kept);
-               if (0 < status)
-                       hit = 1;
-               argc = nr + kept;
+               if (MAXARGS <= argc) {
+                       status = flush_grep(opt, argc, nr, argv, &kept);
+                       if (0 < status)
+                               hit = 1;
+                       argc = nr + kept;
+               }
                if (ce_stage(ce)) {
                        do {
                                i++;