]>
Commit | Line | Data |
---|---|---|
71b5d1c5 | 1 | /* Test re_search with multi-byte characters in EUC-JP. |
688903eb | 2 | Copyright (C) 2012-2018 Free Software Foundation, Inc. |
71b5d1c5 SB |
3 | This file is part of the GNU C Library. |
4 | Contributed by Stanislav Brabec <sbrabec@suse.cz>, 2012. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
c524201a PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
71b5d1c5 SB |
19 | |
20 | #define _GNU_SOURCE 1 | |
21 | #include <locale.h> | |
22 | #include <regex.h> | |
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
25 | #include <string.h> | |
26 | #include "regex_internal.h" | |
27 | ||
28 | static int | |
29 | do_test (void) | |
30 | { | |
31 | struct re_pattern_buffer r; | |
32 | struct re_registers s; | |
33 | int e, rc = 0; | |
34 | if (setlocale (LC_CTYPE, "ja_JP.EUC-JP") == NULL) | |
35 | { | |
36 | puts ("setlocale failed"); | |
37 | return 1; | |
38 | } | |
39 | memset (&r, 0, sizeof (r)); | |
40 | memset (&s, 0, sizeof (s)); | |
41 | ||
42 | /* The bug cannot be reproduced without initialized fastmap. */ | |
43 | r.fastmap = malloc (SBC_MAX); | |
44 | ||
45 | /* 圭 */ | |
46 | re_compile_pattern ("\xb7\xbd", 2, &r); | |
47 | ||
48 | /* aaaaa件a新処, \xb7\xbd constitutes a false match */ | |
49 | e = re_search (&r, "\x61\x61\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8", | |
50 | 12, 0, 12, &s); | |
51 | if (e != -1) | |
52 | { | |
53 | printf ("bug-regex33.1: false match or error: re_search() returned %d, should return -1\n", e); | |
54 | rc = 1; | |
55 | } | |
56 | ||
57 | /* aaaa件a新処, \xb7\xbd constitutes a false match, | |
58 | * this is a reproducer of BZ #13637 */ | |
59 | e = re_search (&r, "\x61\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8", | |
60 | 11, 0, 11, &s); | |
61 | if (e != -1) | |
62 | { | |
63 | printf ("bug-regex33.2: false match or error: re_search() returned %d, should return -1\n", e); | |
64 | rc = 1; | |
65 | } | |
66 | ||
67 | /* aaa件a新処, \xb7\xbd constitutes a false match, | |
68 | * this is a reproducer of BZ #13637 */ | |
69 | e = re_search (&r, "\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8", | |
70 | 10, 0, 10, &s); | |
71 | if (e != -1) | |
72 | { | |
73 | printf ("bug-regex33.3: false match or error: re_search() returned %d, should return -1\n", e); | |
74 | rc = 1; | |
75 | } | |
76 | ||
77 | /* aa件a新処, \xb7\xbd constitutes a false match */ | |
78 | e = re_search (&r, "\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8", | |
79 | 9, 0, 9, &s); | |
80 | if (e != -1) | |
81 | { | |
82 | printf ("bug-regex33.4: false match or error: re_search() returned %d, should return -1\n", e); | |
83 | rc = 1; | |
84 | } | |
85 | ||
86 | /* a件a新処, \xb7\xbd constitutes a false match */ | |
87 | e = re_search (&r, "\x61\xb7\xef\x61\xbf\xb7\xbd\xe8", | |
88 | 8, 0, 8, &s); | |
89 | if (e != -1) | |
90 | { | |
91 | printf ("bug-regex33.5: false match or error: re_search() returned %d, should return -1\n", e); | |
92 | rc = 1; | |
93 | } | |
94 | ||
95 | /* 新処圭新処, \xb7\xbd here really matches 圭, but second occurrence is a false match, | |
96 | * this is a reproducer of bug-regex25 and BZ #13637 */ | |
97 | e = re_search (&r, "\xbf\xb7\xbd\xe8\xb7\xbd\xbf\xb7\xbd\xe8", | |
98 | 10, 0, 10, &s); | |
99 | if (e != 4) | |
100 | { | |
101 | printf ("bug-regex33.6: no match or false match: re_search() returned %d, should return 4\n", e); | |
102 | rc = 1; | |
103 | } | |
104 | ||
105 | /* 新処圭新, \xb7\xbd here really matches 圭, | |
106 | * this is a reproducer of bug-regex25 */ | |
107 | e = re_search (&r, "\xbf\xb7\xbd\xe8\xb7\xbd\xbf\xb7", | |
108 | 10, 0, 10, &s); | |
109 | if (e != 4) | |
110 | { | |
111 | printf ("bug-regex33.7: no match or false match: re_search() returned %d, should return 4\n", e); | |
112 | rc = 1; | |
113 | } | |
114 | ||
115 | return rc; | |
116 | } | |
117 | ||
118 | #define TEST_FUNCTION do_test () | |
119 | #include "../test-skeleton.c" |