File: bug-regex24.c

package info (click to toggle)
glibc 2.19-18+deb8u9
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 204,712 kB
  • ctags: 145,148
  • sloc: ansic: 970,427; asm: 241,207; sh: 10,069; makefile: 8,476; cpp: 3,595; perl: 2,077; pascal: 1,839; awk: 1,704; yacc: 317; sed: 73
file content (60 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (31)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <regex.h>
#include <stdio.h>
#include <string.h>

#define str "civic"

#define N 10
static const char *expected[N] =
  {
    str, "c", "i", "", "", "", "", "", "", ""
  };

static int
do_test (void)
{
  regex_t rbuf;
  static const char pat[] = "\
^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$";

  int err = regcomp (&rbuf, pat, REG_EXTENDED);
  if (err != 0)
    {
      char errstr[300];
      regerror (err, &rbuf, errstr, sizeof (errstr));
      puts (errstr);
      return err;
    }

  regmatch_t m[N];
  err = regexec (&rbuf, str, N, m, 0);
  if (err != 0)
    {
      puts ("regexec failed");
      return 1;
    }

  int result = 0;
  for (int i = 0; i < N; ++i)
    if (m[i].rm_so == -1)
      {
	printf ("m[%d] unused\n", i);
	result = 1;
      }
    else
      {
	int len = m[i].rm_eo - m[i].rm_so;

	printf ("m[%d] = \"%.*s\"\n", i, len, str + m[i].rm_so);

	if (strlen (expected[i]) != len
	    || memcmp (expected[i], str + m[i].rm_so, len) != 0)
	  result = 1;
      }

  return result;
}

#define TIMEOUT 30
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"