summaryrefslogtreecommitdiff
path: root/testsuite/bug-regex15.c
blob: 97fc69d64fea4d60e8ef36ee0d1d3ad26ad928f4 (plain)
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
/* Test for memory/CPU leak in regcomp.  */

#include "config.h"

#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>

#define TEST_DATA_LIMIT (32 << 20)

int
main ()
{
#ifdef RLIMIT_DATA
  regex_t re;
  int reerr;

  /* Try to avoid eating all memory if a test leaks.  */
  struct rlimit data_limit;
  if (getrlimit (RLIMIT_DATA, &data_limit) == 0)
    {
      if ((rlim_t) TEST_DATA_LIMIT > data_limit.rlim_max)
	data_limit.rlim_cur = data_limit.rlim_max;
      else if (data_limit.rlim_cur > (rlim_t) TEST_DATA_LIMIT)
	data_limit.rlim_cur = (rlim_t) TEST_DATA_LIMIT;
      if (setrlimit (RLIMIT_DATA, &data_limit) < 0)
	perror ("setrlimit: RLIMIT_DATA");
    }
  else
    perror ("getrlimit: RLIMIT_DATA");

  reerr = regcomp (&re, "^6?3?[25]?5?[14]*[25]*[69]*+[58]*87?4?$",
		   REG_EXTENDED | REG_NOSUB);
  if (reerr != 0)
    {
      char buf[100];
      regerror (reerr, &re, buf, sizeof buf);
      printf ("regerror %s\n", buf);
      return 1;
    }

  return 0;
#else
  return 77;
#endif
}