Merge "Fix CFI directives in memmove implementation" into main
diff --git a/android-changes-for-ndk-developers.md b/android-changes-for-ndk-developers.md
index a96e105..2430447 100644
--- a/android-changes-for-ndk-developers.md
+++ b/android-changes-for-ndk-developers.md
@@ -534,3 +534,13 @@
 `libc.so`. This ensures that executables built with newer `crtbegin_dynamic.o`
 (in NDK >= r27) work with older `libc.so` (in Android <= API level 34), and
 vice versa.
+
+
+## Only files named `lib*.so` are copied by `extractNativeLibs` (Enforced for API level <= 35)
+
+Until API level 36, PackageManager would only install files whose names match
+the glob `lib*.so` when extracting native libraries _for non-debuggable apps_.
+This was especially confusing (and hard to debug) because the restriction did
+_not_ apply if your app was debuggable. To be compatible with all API levels,
+always give files that need to be extracted a "lib" prefix and ".so" suffix,
+or avoid using `extractNativeLibs`.
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
index b24f4ad..79f946f 100644
--- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
@@ -2581,7 +2581,7 @@
   // Mark only some pages in use.
   uint8_t* data = reinterpret_cast<uint8_t*>(ptr);
   // Make sure the memory is not in use.
-  ASSERT_EQ(0, madvise(ptr, pagesize * 8, MADV_PAGEOUT));
+  ASSERT_EQ(0, madvise(ptr, pagesize * 8, MADV_DONTNEED));
   // Dirty three non-consecutive pages.
   data[0] = 1;
   data[pagesize * 2] = 1;
diff --git a/libc/upstream-netbsd/lib/libc/regex/regcomp.c b/libc/upstream-netbsd/lib/libc/regex/regcomp.c
index 86321c1..b0f29d6 100644
--- a/libc/upstream-netbsd/lib/libc/regex/regcomp.c
+++ b/libc/upstream-netbsd/lib/libc/regex/regcomp.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: regcomp.c,v 1.47 2022/12/21 17:44:15 wiz Exp $	*/
+/*	$NetBSD: regcomp.c,v 1.49 2025/01/01 18:19:50 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-3-Clause
@@ -51,7 +51,7 @@
 static char sccsid[] = "@(#)regcomp.c	8.5 (Berkeley) 3/20/94";
 __FBSDID("$FreeBSD: head/lib/libc/regex/regcomp.c 368359 2020-12-05 03:18:48Z kevans $");
 #endif
-__RCSID("$NetBSD: regcomp.c,v 1.47 2022/12/21 17:44:15 wiz Exp $");
+__RCSID("$NetBSD: regcomp.c,v 1.49 2025/01/01 18:19:50 christos Exp $");
 
 #ifndef LIBHACK
 #define REGEX_GNU_EXTENSIONS
@@ -898,10 +898,10 @@
 	handled = false;
 
 	assert(MORE());		/* caller should have ensured this */
-	c = GETNEXT();
+	c = (uch)GETNEXT();
 	if (c == '\\') {
 		(void)REQUIRE(MORE(), REG_EESCAPE);
-		cc = GETNEXT();
+		cc = (uch)GETNEXT();
 		c = BACKSL | cc;
 #ifdef REGEX_GNU_EXTENSIONS
 		if (p->gnuext) {
@@ -1083,7 +1083,7 @@
 	int ndigits = 0;
 
 	while (MORE() && isdigit((uch)PEEK()) && count <= DUPMAX) {
-		count = count*10 + (GETNEXT() - '0');
+		count = count*10 + ((uch)GETNEXT() - '0');
 		ndigits++;
 	}
 
@@ -1422,7 +1422,7 @@
 
 	if ((p->pflags & PFLAG_LEGACY_ESC) != 0)
 		return (true);
-	if (isalpha(ch) || ch == '\'' || ch == '`')
+	if (iswalpha(ch) || ch == '\'' || ch == '`')
 		return (false);
 	return (true);
 #ifdef NOTYET
@@ -1764,8 +1764,7 @@
 	_DIAGASSERT(p != NULL);
 	_DIAGASSERT(cs != NULL);
 
-	assert(ch >= 0);
-	if (ch < NC)
+	if ((unsigned)ch < NC)
 		cs->bmp[(unsigned)ch >> 3] |= 1 << (ch & 7);
 	else {
 		newwides = reallocarray(cs->wides, cs->nwides + 1,
@@ -1778,9 +1777,9 @@
 		cs->wides[cs->nwides++] = ch;
 	}
 	if (cs->icase) {
-		if ((nch = towlower(ch)) < NC)
+		if ((unsigned)(nch = towlower(ch)) < NC)
 			cs->bmp[(unsigned)nch >> 3] |= 1 << (nch & 7);
-		if ((nch = towupper(ch)) < NC)
+		if ((unsigned)(nch = towupper(ch)) < NC)
 			cs->bmp[(unsigned)nch >> 3] |= 1 << (nch & 7);
 	}
 }
diff --git a/libc/upstream-netbsd/lib/libc/regex/regex2.h b/libc/upstream-netbsd/lib/libc/regex/regex2.h
index fbfff0d..d44785f 100644
--- a/libc/upstream-netbsd/lib/libc/regex/regex2.h
+++ b/libc/upstream-netbsd/lib/libc/regex/regex2.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: regex2.h,v 1.15 2021/02/24 18:13:21 christos Exp $	*/
+/*	$NetBSD: regex2.h,v 1.16 2025/01/01 18:19:50 christos Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-3-Clause
@@ -135,8 +135,7 @@
 {
 	unsigned int i;
 
-	assert(ch >= 0);
-	if (ch < NC)
+	if ((unsigned)ch < NC)
 		return (((cs->bmp[(unsigned)ch >> 3] & (1 << (ch & 7))) != 0) ^
 		    cs->invert);
 	for (i = 0; i < cs->nwides; i++) {
@@ -160,8 +159,7 @@
 CHIN(cset *cs, wint_t ch)
 {
 
-	assert(ch >= 0);
-	if (ch < NC)
+	if ((unsigned)ch < NC)
 		return (((cs->bmp[(unsigned)ch >> 3] & (1 << (ch & 7))) != 0) ^
 		    cs->invert);
 	else if (cs->icase)
diff --git a/tests/complex_test.cpp b/tests/complex_test.cpp
index ed0109a..456efa7 100644
--- a/tests/complex_test.cpp
+++ b/tests/complex_test.cpp
@@ -28,6 +28,10 @@
 // have to be naughty.
 #include "../libc/include/complex.h"
 
+// Ensure that libc++'s complex.h and __fwd/complex.h headers are no-ops.
+#define _LIBCPP_COMPLEX_H
+#define _LIBCPP___FWD_COMPLEX_H
+
 // (libc++ also seems to have really bad implementations of its own that ignore
 // the intricacies of floating point math.)
 // http://llvm.org/bugs/show_bug.cgi?id=21504