VirtualBox

source: kBuild/vendor/sed/4.1.5/testsuite/bug-regex15.c@ 599

Last change on this file since 599 was 599, checked in by bird, 18 years ago

GNU sed 4.1.5.

File size: 1.0 KB
Line 
1/* Test for memory/CPU leak in regcomp. */
2
3#include <sys/types.h>
4#include <sys/time.h>
5#include <sys/resource.h>
6#include <regex.h>
7#include <stdio.h>
8#include <stdlib.h>
9
10#define TEST_DATA_LIMIT (32 << 20)
11
12int
13main ()
14{
15#ifdef RLIMIT_DATA
16 regex_t re;
17 int reerr;
18
19 /* Try to avoid eating all memory if a test leaks. */
20 struct rlimit data_limit;
21 if (getrlimit (RLIMIT_DATA, &data_limit) == 0)
22 {
23 if ((rlim_t) TEST_DATA_LIMIT > data_limit.rlim_max)
24 data_limit.rlim_cur = data_limit.rlim_max;
25 else if (data_limit.rlim_cur > (rlim_t) TEST_DATA_LIMIT)
26 data_limit.rlim_cur = (rlim_t) TEST_DATA_LIMIT;
27 if (setrlimit (RLIMIT_DATA, &data_limit) < 0)
28 perror ("setrlimit: RLIMIT_DATA");
29 }
30 else
31 perror ("getrlimit: RLIMIT_DATA");
32
33 reerr = regcomp (&re, "^6?3?[25]?5?[14]*[25]*[69]*+[58]*87?4?$",
34 REG_EXTENDED | REG_NOSUB);
35 if (reerr != 0)
36 {
37 char buf[100];
38 regerror (reerr, &re, buf, sizeof buf);
39 printf ("regerror %s\n", buf);
40 return 1;
41 }
42
43 return 0;
44#else
45 return 77;
46#endif
47}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette