1/* Test re_search with multi-byte characters in EUC-JP.
2 Copyright (C) 2012-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#define _GNU_SOURCE 1
20#include <locale.h>
21#include <regex.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26static int
27do_test (void)
28{
29 struct re_pattern_buffer r;
30 struct re_registers s;
31 int e, rc = 0;
32 if (setlocale (LC_CTYPE, "ja_JP.EUC-JP") == NULL)
33 {
34 puts (s: "setlocale failed");
35 return 1;
36 }
37 memset (&r, 0, sizeof (r));
38 memset (&s, 0, sizeof (s));
39
40 /* The bug cannot be reproduced without initialized fastmap (it is SBC_MAX
41 value from regex_internal.h). */
42 r.fastmap = malloc (UCHAR_MAX + 1);
43
44 /* 圭 */
45 re_compile_pattern (pattern: "\xb7\xbd", length: 2, buffer: &r);
46
47 /* aaaaa件a新処, \xb7\xbd constitutes a false match */
48 e = re_search (buffer: &r, String: "\x61\x61\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
49 length: 12, start: 0, range: 12, regs: &s);
50 if (e != -1)
51 {
52 printf (format: "bug-regex33.1: false match or error: re_search() returned %d, should return -1\n", e);
53 rc = 1;
54 }
55
56 /* aaaa件a新処, \xb7\xbd constitutes a false match,
57 * this is a reproducer of BZ #13637 */
58 e = re_search (buffer: &r, String: "\x61\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
59 length: 11, start: 0, range: 11, regs: &s);
60 if (e != -1)
61 {
62 printf (format: "bug-regex33.2: false match or error: re_search() returned %d, should return -1\n", e);
63 rc = 1;
64 }
65
66 /* aaa件a新処, \xb7\xbd constitutes a false match,
67 * this is a reproducer of BZ #13637 */
68 e = re_search (buffer: &r, String: "\x61\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
69 length: 10, start: 0, range: 10, regs: &s);
70 if (e != -1)
71 {
72 printf (format: "bug-regex33.3: false match or error: re_search() returned %d, should return -1\n", e);
73 rc = 1;
74 }
75
76 /* aa件a新処, \xb7\xbd constitutes a false match */
77 e = re_search (buffer: &r, String: "\x61\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
78 length: 9, start: 0, range: 9, regs: &s);
79 if (e != -1)
80 {
81 printf (format: "bug-regex33.4: false match or error: re_search() returned %d, should return -1\n", e);
82 rc = 1;
83 }
84
85 /* a件a新処, \xb7\xbd constitutes a false match */
86 e = re_search (buffer: &r, String: "\x61\xb7\xef\x61\xbf\xb7\xbd\xe8",
87 length: 8, start: 0, range: 8, regs: &s);
88 if (e != -1)
89 {
90 printf (format: "bug-regex33.5: false match or error: re_search() returned %d, should return -1\n", e);
91 rc = 1;
92 }
93
94 /* 新処圭新処, \xb7\xbd here really matches 圭, but second occurrence is a false match,
95 * this is a reproducer of bug-regex25 and BZ #13637 */
96 e = re_search (buffer: &r, String: "\xbf\xb7\xbd\xe8\xb7\xbd\xbf\xb7\xbd\xe8",
97 length: 10, start: 0, range: 10, regs: &s);
98 if (e != 4)
99 {
100 printf (format: "bug-regex33.6: no match or false match: re_search() returned %d, should return 4\n", e);
101 rc = 1;
102 }
103
104 /* 新処圭新, \xb7\xbd here really matches 圭,
105 * this is a reproducer of bug-regex25 */
106 e = re_search (buffer: &r, String: "\xbf\xb7\xbd\xe8\xb7\xbd\xbf\xb7",
107 length: 9, start: 0, range: 9, regs: &s);
108 if (e != 4)
109 {
110 printf (format: "bug-regex33.7: no match or false match: re_search() returned %d, should return 4\n", e);
111 rc = 1;
112 }
113
114 return rc;
115}
116
117#define TEST_FUNCTION do_test ()
118#include "../test-skeleton.c"
119

source code of glibc/posix/bug-regex33.c