Avoid SIGFPE in wordexp [BZ #18100]
[glibc.git] / posix / bug-regex22.c
blob673bae10ba647286e9cc86c3adba480438066cfc
1 /* Test re.translate != NULL.
2 Copyright (C) 2004-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <ctype.h>
21 #include <locale.h>
22 #include <regex.h>
23 #include <stdio.h>
24 #include <string.h>
26 int
27 main (void)
29 struct re_pattern_buffer re;
30 char trans[256];
31 int i, result = 0;
32 const char *s;
34 setlocale (LC_ALL, "de_DE.ISO-8859-1");
36 for (i = 0; i < 256; ++i)
37 trans[i] = tolower (i);
39 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
41 memset (&re, 0, sizeof (re));
42 re.translate = (unsigned char *) trans;
43 s = re_compile_pattern ("\\W", 2, &re);
45 if (s != NULL)
47 printf ("failed to compile pattern \"\\W\": %s\n", s);
48 result = 1;
50 else
52 int ret = re_search (&re, "abc.de", 6, 0, 6, NULL);
53 if (ret != 3)
55 printf ("1st re_search returned %d\n", ret);
56 result = 1;
59 ret = re_search (&re, "\xc4\xd6\xae\xf7", 4, 0, 4, NULL);
60 if (ret != 2)
62 printf ("2nd re_search returned %d\n", ret);
63 result = 1;
65 re.translate = NULL;
66 regfree (&re);
69 memset (&re, 0, sizeof (re));
70 re.translate = (unsigned char *) trans;
71 s = re_compile_pattern ("\\w", 2, &re);
73 if (s != NULL)
75 printf ("failed to compile pattern \"\\w\": %s\n", s);
76 result = 1;
78 else
80 int ret = re_search (&re, ".,!abc", 6, 0, 6, NULL);
81 if (ret != 3)
83 printf ("3rd re_search returned %d\n", ret);
84 result = 1;
87 ret = re_search (&re, "\xae\xf7\xc4\xd6", 4, 0, 4, NULL);
88 if (ret != 2)
90 printf ("4th re_search returned %d\n", ret);
91 result = 1;
93 re.translate = NULL;
94 regfree (&re);
97 memset (&re, 0, sizeof (re));
98 re.translate = (unsigned char *) trans;
99 s = re_compile_pattern ("[[:DIGIT:]]", 11, &re);
100 if (s == NULL)
102 printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n",
104 result = 1;
107 memset (&re, 0, sizeof (re));
108 re.translate = (unsigned char *) trans;
109 s = re_compile_pattern ("[[:DIGIT:]]", 2, &re);
110 if (s == NULL)
112 printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n",
114 result = 1;
117 return result;