Skip to content

Commit dabdc01

Browse files
committed
Merge branch 'rj/test-regex' into maint-1.7.11
* rj/test-regex: test-regex: Add a test to check for a bug in the regex routines
2 parents f463cc5 + c918415 commit dabdc01

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
@@ -186,6 +186,7 @@
186186
/test-mktemp
187187
/test-parse-options
188188
/test-path-utils
189+
/test-regex
189190
/test-revision-walking
190191
/test-run-command
191192
/test-sha1

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort
495495
TEST_PROGRAMS_NEED_X += test-mktemp
496496
TEST_PROGRAMS_NEED_X += test-parse-options
497497
TEST_PROGRAMS_NEED_X += test-path-utils
498+
TEST_PROGRAMS_NEED_X += test-regex
498499
TEST_PROGRAMS_NEED_X += test-revision-walking
499500
TEST_PROGRAMS_NEED_X += test-run-command
500501
TEST_PROGRAMS_NEED_X += test-scrap-cache-tree

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)