Module Name:    src
Committed By:   riastradh
Date:           Fri Mar 28 18:54:10 UTC 2025

Modified Files:
        src/tests/lib/libc/gen: t_ctype.c

Log Message:
t_ctype: Fix tests on platforms where char is unsigned.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/gen/t_ctype.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/gen/t_ctype.c
diff -u src/tests/lib/libc/gen/t_ctype.c:1.1 src/tests/lib/libc/gen/t_ctype.c:1.2
--- src/tests/lib/libc/gen/t_ctype.c:1.1	Fri Mar 28 18:41:55 2025
+++ src/tests/lib/libc/gen/t_ctype.c	Fri Mar 28 18:54:09 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ctype.c,v 1.1 2025/03/28 18:41:55 riastradh Exp $	*/
+/*	$NetBSD: t_ctype.c,v 1.2 2025/03/28 18:54:09 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2025 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ctype.c,v 1.1 2025/03/28 18:41:55 riastradh Exp $");
+__RCSID("$NetBSD: t_ctype.c,v 1.2 2025/03/28 18:54:09 riastradh Exp $");
 
 #include <atf-c.h>
 #include <ctype.h>
@@ -39,6 +39,12 @@ __RCSID("$NetBSD: t_ctype.c,v 1.1 2025/0
 
 #include "h_macros.h"
 
+#ifdef __CHAR_UNSIGNED__
+enum { CHAR_UNSIGNED = 1 };
+#else
+enum { CHAR_UNSIGNED = 0 };
+#endif
+
 static const char *locales[] = { "C.UTF-8", "fr_FR.ISO8859-1" };
 
 static int isalpha_wrapper(int ch) { return isalpha(ch); }
@@ -56,7 +62,6 @@ static int isblank_wrapper(int ch) { ret
 static int toupper_wrapper(int ch) { return toupper(ch); }
 static int tolower_wrapper(int ch) { return tolower(ch); }
 
-#ifndef __CHAR_UNSIGNED__
 jmp_buf env;
 
 static void
@@ -65,14 +70,10 @@ handle_sigsegv(int signo)
 
 	longjmp(env, 1);
 }
-#endif
 
 static void
 test_abuse(const char *name, int (*ctypefn)(int))
 {
-#ifdef __CHAR_UNSIGNED__
-	atf_tc_skip("runtime ctype(3) abuse is impossible with unsigned char");
-#else
 	volatile int ch;	/* for longjmp */
 
 	for (ch = CHAR_MIN; ch < 0; ch++) {
@@ -97,7 +98,6 @@ test_abuse(const char *name, int (*ctype
 
 	for (; ch <= CHAR_MAX; ch++)
 		ATF_REQUIRE_MSG(ch == (int)(unsigned char)ch, "ch=%d", ch);
-#endif
 }
 
 static void
@@ -762,6 +762,10 @@ ATF_TC_HEAD(abuse_##FN##_macro_c, tc)			
 }									      \
 ATF_TC_BODY(abuse_##FN##_macro_c, tc)					      \
 {									      \
+	if (CHAR_UNSIGNED) {						      \
+		atf_tc_skip("runtime ctype(3) abuse is impossible with"	      \
+		    " unsigned char");					      \
+	}								      \
 	atf_tc_expect_fail("PR lib/58208:"				      \
 	    " ctype(3) provides poor runtime feedback of abuse");	      \
 	test_abuse(#FN, &FN##_wrapper);					      \
@@ -774,6 +778,10 @@ ATF_TC_HEAD(abuse_##FN##_function_c, tc)
 }									      \
 ATF_TC_BODY(abuse_##FN##_function_c, tc)				      \
 {									      \
+	if (CHAR_UNSIGNED) {						      \
+		atf_tc_skip("runtime ctype(3) abuse is impossible with"	      \
+		    " unsigned char");					      \
+	}								      \
 	atf_tc_expect_fail("PR lib/58208:"				      \
 	    " ctype(3) provides poor runtime feedback of abuse");	      \
 	test_abuse(#FN, &FN);						      \
@@ -788,6 +796,10 @@ ATF_TC_BODY(abuse_##FN##_macro_locale, t
 {									      \
 	size_t i;							      \
 									      \
+	if (CHAR_UNSIGNED) {						      \
+		atf_tc_skip("runtime ctype(3) abuse is impossible with"	      \
+		    " unsigned char");					      \
+	}								      \
 	atf_tc_expect_fail("PR lib/58208:"				      \
 	    " ctype(3) provides poor runtime feedback of abuse");	      \
 	for (i = 0; i < __arraycount(locales); i++) {			      \
@@ -809,6 +821,10 @@ ATF_TC_BODY(abuse_##FN##_function_locale
 {									      \
 	size_t i;							      \
 									      \
+	if (CHAR_UNSIGNED) {						      \
+		atf_tc_skip("runtime ctype(3) abuse is impossible with"	      \
+		    " unsigned char");					      \
+	}								      \
 	atf_tc_expect_fail("PR lib/58208:"				      \
 	    " ctype(3) provides poor runtime feedback of abuse");	      \
 	for (i = 0; i < __arraycount(locales); i++) {			      \

Reply via email to