Back to index

glibc  2.9
Defines | Functions | Variables
bug-regex24.c File Reference
#include <regex.h>
#include <stdio.h>
#include <string.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define str   "civic"
#define N   10
#define TIMEOUT   30
#define TEST_FUNCTION   do_test ()

Functions

static int do_test (void)

Variables

static const char * expected [N]

Define Documentation

#define N   10

Definition at line 7 of file bug-regex24.c.

#define str   "civic"

Definition at line 5 of file bug-regex24.c.

#define TEST_FUNCTION   do_test ()

Definition at line 59 of file bug-regex24.c.

#define TIMEOUT   30

Definition at line 58 of file bug-regex24.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 14 of file bug-regex24.c.

{
  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;
}

Here is the call graph for this function:


Variable Documentation

const char* expected[N] [static]
Initial value:
  {
    str, "c", "i", "", "", "", "", "", "", ""
  }

Definition at line 8 of file bug-regex24.c.