summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0a0c342)
raw | patch | inline | side by side (parent: 0a0c342)
author | Matt Kraai <kraai@ftbfs.org> | |
Fri, 16 Oct 2009 14:13:25 +0000 (07:13 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 17 Oct 2009 06:47:47 +0000 (23:47 -0700) |
"git grep" would segfault if its -f option was used because it would
try to use an uninitialized strbuf, so initialize the strbuf.
Thanks to Johannes Sixt <j.sixt@viscovery.net> for the help with the
test cases.
Signed-off-by: Matt Kraai <kraai@ftbfs.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
try to use an uninitialized strbuf, so initialize the strbuf.
Thanks to Johannes Sixt <j.sixt@viscovery.net> for the help with the
test cases.
Signed-off-by: Matt Kraai <kraai@ftbfs.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-grep.c | patch | blob | history | |
t/t7002-grep.sh | patch | blob | history |
diff --git a/builtin-grep.c b/builtin-grep.c
index fd450bc16e56a634b14cfa33f77e5192412643d8..e3b940b93334f99f610f84a86c9da11a435d1365 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
struct grep_opt *grep_opt = opt->value;
FILE *patterns;
int lno = 0;
- struct strbuf sb;
+ struct strbuf sb = STRBUF_INIT;
patterns = fopen(arg, "r");
if (!patterns)
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index 6ca11d71465aa609232614bbbd360955869e0776..5f91d822971180aebbd9503466a3b14db79b8bc6 100755 (executable)
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
test_cmp expected actual
'
+test_expect_success 'grep -f, non-existent file' '
+ test_must_fail git grep -f patterns
+'
+
+cat >expected <<EOF
+file:foo mmap bar
+file:foo_mmap bar
+file:foo_mmap bar mmap
+file:foo mmap bar_mmap
+file:foo_mmap bar mmap baz
+EOF
+
+cat >pattern <<EOF
+mmap
+EOF
+
+test_expect_success 'grep -f, one pattern' '
+ git grep -f pattern >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF
+file:foo mmap bar
+file:foo_mmap bar
+file:foo_mmap bar mmap
+file:foo mmap bar_mmap
+file:foo_mmap bar mmap baz
+t/a/v:vvv
+t/v:vvv
+v:vvv
+EOF
+
+cat >patterns <<EOF
+mmap
+vvv
+EOF
+
+test_expect_success 'grep -f, multiple patterns' '
+ git grep -f patterns >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF
+file:foo mmap bar
+file:foo_mmap bar
+file:foo_mmap bar mmap
+file:foo mmap bar_mmap
+file:foo_mmap bar mmap baz
+t/a/v:vvv
+t/v:vvv
+v:vvv
+EOF
+
+cat >patterns <<EOF
+
+mmap
+
+vvv
+
+EOF
+
+test_expect_success 'grep -f, ignore empty lines' '
+ git grep -f patterns >actual &&
+ test_cmp expected actual
+'
+
cat >expected <<EOF
y:y yy
--