Skip to content

Commit c918415

Browse files
Ramsay Jonesgitster
authored andcommitted
test-regex: Add a test to check for a bug in the regex routines
Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0f1ea6 commit c918415

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
/test-obj-pool
185185
/test-parse-options
186186
/test-path-utils
187+
/test-regex
187188
/test-run-command
188189
/test-sha1
189190
/test-sigchain

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ TEST_PROGRAMS_NEED_X += test-mktemp
476476
TEST_PROGRAMS_NEED_X += test-obj-pool
477477
TEST_PROGRAMS_NEED_X += test-parse-options
478478
TEST_PROGRAMS_NEED_X += test-path-utils
479+
TEST_PROGRAMS_NEED_X += test-regex
479480
TEST_PROGRAMS_NEED_X += test-run-command
480481
TEST_PROGRAMS_NEED_X += test-sha1
481482
TEST_PROGRAMS_NEED_X += test-sigchain

t/t0070-fundamental.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ test_expect_success POSIXPERM 'mktemp to unwritable directory prints filename' '
2525
grep "cannotwrite/test" err
2626
'
2727

28+
test_expect_success 'check for a bug in the regex routines' '
29+
# if this test fails, re-build git with NO_REGEX=1
30+
test-regex
31+
'
32+
2833
test_done

test-regex.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <git-compat-util.h>
2+
3+
int main(int argc, char **argv)
4+
{
5+
char *pat = "[^={} \t]+";
6+
char *str = "={}\nfred";
7+
regex_t r;
8+
regmatch_t m[1];
9+
10+
if (regcomp(&r, pat, REG_EXTENDED | REG_NEWLINE))
11+
die("failed regcomp() for pattern '%s'", pat);
12+
if (regexec(&r, str, 1, m, 0))
13+
die("no match of pattern '%s' to string '%s'", pat, str);
14+
15+
/* http://sourceware.org/bugzilla/show_bug.cgi?id=3957 */
16+
if (m[0].rm_so == 3) /* matches '\n' when it should not */
17+
die("regex bug confirmed: re-build git with NO_REGEX=1");
18+
19+
exit(0);
20+
}

0 commit comments

Comments
 (0)