Changes for #inclusivefixit.
Test: treehugger
Change-Id: I7ff0496c5c2792a41781e74634247f55b0548213
diff --git a/libc/arch-x86/bionic/__libc_init_sysinfo.cpp b/libc/arch-x86/bionic/__libc_init_sysinfo.cpp
index 5c44b4e..db931d1 100644
--- a/libc/arch-x86/bionic/__libc_init_sysinfo.cpp
+++ b/libc/arch-x86/bionic/__libc_init_sysinfo.cpp
@@ -37,8 +37,8 @@
}
__LIBC_HIDDEN__ void __libc_init_sysinfo() {
- bool dummy;
- __libc_sysinfo = reinterpret_cast<void*>(__bionic_getauxval(AT_SYSINFO, dummy));
+ bool unused;
+ __libc_sysinfo = reinterpret_cast<void*>(__bionic_getauxval(AT_SYSINFO, &unused));
}
// TODO: lose this function and just access __libc_sysinfo directly.
diff --git a/libc/bionic/getauxval.cpp b/libc/bionic/getauxval.cpp
index d6f75f8..a3c6b19 100644
--- a/libc/bionic/getauxval.cpp
+++ b/libc/bionic/getauxval.cpp
@@ -37,20 +37,20 @@
// This function needs to be safe to call before TLS is set up, so it can't
// access errno or the stack protector.
-__LIBC_HIDDEN__ unsigned long __bionic_getauxval(unsigned long type, bool& exists) {
+__LIBC_HIDDEN__ unsigned long __bionic_getauxval(unsigned long type, bool* exists) {
for (ElfW(auxv_t)* v = __libc_shared_globals()->auxv; v->a_type != AT_NULL; ++v) {
if (v->a_type == type) {
- exists = true;
+ *exists = true;
return v->a_un.a_val;
}
}
- exists = false;
+ *exists = false;
return 0;
}
extern "C" unsigned long getauxval(unsigned long type) {
bool exists;
- unsigned long result = __bionic_getauxval(type, exists);
+ unsigned long result = __bionic_getauxval(type, &exists);
if (!exists) errno = ENOENT;
return result;
}
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 1ede969..f1350d5 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -359,10 +359,8 @@
Dtor* fini_array = reinterpret_cast<Dtor*>(array);
const Dtor minus1 = reinterpret_cast<Dtor>(static_cast<uintptr_t>(-1));
- // Sanity check - first entry must be -1.
- if (array == nullptr || fini_array[0] != minus1) {
- return;
- }
+ // Validity check: the first entry must be -1.
+ if (array == nullptr || fini_array[0] != minus1) return;
// Skip over it.
fini_array += 1;
@@ -373,15 +371,9 @@
++count;
}
- // Now call each destructor in reverse order.
+ // Now call each destructor in reverse order, ignoring any -1s.
while (count > 0) {
Dtor dtor = fini_array[--count];
-
- // Sanity check, any -1 in the list is ignored.
- if (dtor == minus1) {
- continue;
- }
-
- dtor();
+ if (dtor != minus1) dtor();
}
}
diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp
index 1551c1f..89aa289 100644
--- a/libc/bionic/pthread_attr.cpp
+++ b/libc/bionic/pthread_attr.cpp
@@ -192,7 +192,8 @@
return errno;
}
- // If the current RLIMIT_STACK is RLIM_INFINITY, only admit to an 8MiB stack for sanity's sake.
+ // If the current RLIMIT_STACK is RLIM_INFINITY, only admit to an 8MiB stack
+ // in case callers such as ART take infinity too literally.
if (stack_limit.rlim_cur == RLIM_INFINITY) {
stack_limit.rlim_cur = 8 * 1024 * 1024;
}
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index d4a8bef..c528105 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -350,7 +350,7 @@
return 0;
}
-// A dummy start routine for pthread_create failures where we've created a thread but aren't
+// A no-op start routine for pthread_create failures where we've created a thread but aren't
// going to run user code on it. We swap out the user's start routine for this and take advantage
// of the regular thread teardown to free up resources.
static void* __do_nothing(void*) {
diff --git a/libc/bionic/sysinfo.cpp b/libc/bionic/sysinfo.cpp
index 1d1070e..7ab8e9e 100644
--- a/libc/bionic/sysinfo.cpp
+++ b/libc/bionic/sysinfo.cpp
@@ -38,9 +38,10 @@
static bool __matches_cpuN(const char* s) {
// The %c trick is to ensure that we have the anchored match "^cpu[0-9]+$".
+ // We can't use %*c because the return value is how many were *assigned*.
unsigned cpu;
- char dummy;
- return (sscanf(s, "cpu%u%c", &cpu, &dummy) == 1);
+ char unused;
+ return (sscanf(s, "cpu%u%c", &cpu, &unused) == 1);
}
int get_nprocs_conf() {
diff --git a/libc/include/nl_types.h b/libc/include/nl_types.h
index 622880a..1c80e4e 100644
--- a/libc/include/nl_types.h
+++ b/libc/include/nl_types.h
@@ -32,7 +32,7 @@
* @file nl_types.h
* @brief Message catalogs.
*
- * Android offers a dummy implementation of these functions to ease porting of historical software.
+ * Android offers a no-op implementation of these functions to ease porting of historical software.
*/
#include <sys/cdefs.h>
diff --git a/libc/private/bionic_auxv.h b/libc/private/bionic_auxv.h
index 8e33c1c..9d2cfdd 100644
--- a/libc/private/bionic_auxv.h
+++ b/libc/private/bionic_auxv.h
@@ -30,4 +30,4 @@
#include <sys/cdefs.h>
-__LIBC_HIDDEN__ unsigned long __bionic_getauxval(unsigned long type, bool& exists);
+__LIBC_HIDDEN__ unsigned long __bionic_getauxval(unsigned long type, bool* exists);
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index 1ecf122..12f3bf5 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -259,7 +259,7 @@
size_t parsefloat(FILE*, char*, char*);
size_t wparsefloat(FILE*, wchar_t*, wchar_t*);
-// Sanity check a FILE* for nullptr, so we can emit a message while crashing
+// Check a FILE* isn't nullptr, so we can emit a message while crashing
// instead of doing a blind null-dereference.
#define CHECK_FP(fp) \
if (fp == nullptr) __fortify_fatal("%s: null FILE*", __FUNCTION__)
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index a0b4219..afc2c48 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -1026,9 +1026,9 @@
__check_count("vsnprintf", "size", n);
// Stdio internals do not deal correctly with zero length buffer.
- char dummy;
+ char one_byte_buffer[1];
if (n == 0) {
- s = &dummy;
+ s = one_byte_buffer;
n = 1;
}