67a1a650672478d4453fcfe6272fad4be749fdd4
   1#include "git-compat-util.h"
   2
   3static int test_regex_bug(void)
   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        return 0;
  20}
  21
  22int main(int argc, char **argv)
  23{
  24        if (argc == 2 && !strcmp(argv[1], "--bug"))
  25                return test_regex_bug();
  26        else
  27                usage("test-regex --bug");
  28}