xref: /netbsd-src/tests/lib/libc/regex/t_regex_binary.c (revision 7ecabda137adac222e49352c1deaf19965a737bf)
1*7ecabda1Schristos /*	$NetBSD: t_regex_binary.c,v 1.1 2025/01/01 18:13:48 christos Exp $	*/
2*7ecabda1Schristos 
3*7ecabda1Schristos /*-
4*7ecabda1Schristos  * Copyright (c) 2024 The NetBSD Foundation, Inc.
5*7ecabda1Schristos  * All rights reserved.
6*7ecabda1Schristos  *
7*7ecabda1Schristos  * This code is derived from software contributed to The NetBSD Foundation
8*7ecabda1Schristos  * by Christos Zoulas.
9*7ecabda1Schristos  *
10*7ecabda1Schristos  * Redistribution and use in source and binary forms, with or without
11*7ecabda1Schristos  * modification, are permitted provided that the following conditions
12*7ecabda1Schristos  * are met:
13*7ecabda1Schristos  * 1. Redistributions of source code must retain the above copyright
14*7ecabda1Schristos  *    notice, this list of conditions and the following disclaimer.
15*7ecabda1Schristos  * 2. Redistributions in binary form must reproduce the above copyright
16*7ecabda1Schristos  *    notice, this list of conditions and the following disclaimer in the
17*7ecabda1Schristos  *    documentation and/or other materials provided with the distribution.
18*7ecabda1Schristos  *
19*7ecabda1Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*7ecabda1Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*7ecabda1Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*7ecabda1Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*7ecabda1Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*7ecabda1Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*7ecabda1Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*7ecabda1Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*7ecabda1Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*7ecabda1Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*7ecabda1Schristos  * POSSIBILITY OF SUCH DAMAGE.
30*7ecabda1Schristos  */
31*7ecabda1Schristos 
32*7ecabda1Schristos #include <sys/cdefs.h>
33*7ecabda1Schristos __RCSID("$NetBSD: t_regex_binary.c,v 1.1 2025/01/01 18:13:48 christos Exp $");
34*7ecabda1Schristos 
35*7ecabda1Schristos #include <atf-c.h>
36*7ecabda1Schristos #include <regex.h>
37*7ecabda1Schristos 
38*7ecabda1Schristos ATF_TC(negative_ranges);
39*7ecabda1Schristos ATF_TC_HEAD(negative_ranges, tc)
40*7ecabda1Schristos {
41*7ecabda1Schristos 	atf_tc_set_md_var(tc, "descr", "Test negative ranges compilation");
42*7ecabda1Schristos }
43*7ecabda1Schristos ATF_TC_BODY(negative_ranges, tc)
44*7ecabda1Schristos {
45*7ecabda1Schristos 	regex_t re;
46*7ecabda1Schristos 	char msg[1024];
47*7ecabda1Schristos 	int e;
48*7ecabda1Schristos 
49*7ecabda1Schristos 	if ((e = regcomp(&re, "[\xe0-\xf1][\xa0-\xd1].*", REG_EXTENDED)) != 0) {
50*7ecabda1Schristos 		regerror(e, &re, msg, sizeof(msg));
51*7ecabda1Schristos 		ATF_REQUIRE_MSG(0, "regcomp failed %s", msg);
52*7ecabda1Schristos 	}
53*7ecabda1Schristos }
54*7ecabda1Schristos 
55*7ecabda1Schristos ATF_TC(negative_char);
56*7ecabda1Schristos ATF_TC_HEAD(negative_char, tc)
57*7ecabda1Schristos {
58*7ecabda1Schristos 	atf_tc_set_md_var(tc, "descr",
59*7ecabda1Schristos 	    "Test negative char in braces compilation");
60*7ecabda1Schristos }
61*7ecabda1Schristos ATF_TC_BODY(negative_char, tc)
62*7ecabda1Schristos {
63*7ecabda1Schristos 	regex_t re;
64*7ecabda1Schristos 	char msg[1024];
65*7ecabda1Schristos 	int e;
66*7ecabda1Schristos 
67*7ecabda1Schristos 	/* PR/58910 */
68*7ecabda1Schristos 	if ((e = regcomp(&re, ": j:[]j:[]j:[\xd9j:[]", REG_EXTENDED)) != 0) {
69*7ecabda1Schristos 		regerror(e, &re, msg, sizeof(msg));
70*7ecabda1Schristos 		ATF_REQUIRE_MSG(0, "regcomp failed %s", msg);
71*7ecabda1Schristos 	}
72*7ecabda1Schristos }
73*7ecabda1Schristos 
74*7ecabda1Schristos ATF_TP_ADD_TCS(tp)
75*7ecabda1Schristos {
76*7ecabda1Schristos 
77*7ecabda1Schristos 	ATF_TP_ADD_TC(tp, negative_ranges);
78*7ecabda1Schristos 	ATF_TP_ADD_TC(tp, negative_char);
79*7ecabda1Schristos 	return atf_no_error();
80*7ecabda1Schristos }
81