summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 78e6947)
raw | patch | inline | side by side (parent: 78e6947)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 18 Nov 2007 05:18:14 +0000 (21:18 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 18 Nov 2007 05:19:55 +0000 (21:19 -0800) |
When building command line to invoke external grep, the
arguments to -A/-B/-C options were placd in randarg[] buffer,
but the code forgot that snprintf() does not count terminating
NUL in its return value. This caused "git grep -A1 -B2" to
invoke external grep with "-B21 -A1".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
arguments to -A/-B/-C options were placd in randarg[] buffer,
but the code forgot that snprintf() does not count terminating
NUL in its return value. This caused "git grep -A1 -B2" to
invoke external grep with "-B21 -A1".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-grep.c | patch | blob | history |
diff --git a/builtin-grep.c b/builtin-grep.c
index 185876b0a6dc191bb5adc22cd5c2f012cd70e479..bbf747fc7b66f6b4f19d9dc62a9ba10965199917 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
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);
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);
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);