summaryrefslogtreecommitdiffstats
path: root/libc/bionic/libc_init_common.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/bionic/libc_init_common.cpp')
-rw-r--r--libc/bionic/libc_init_common.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 94b7dd2..f82ec73 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -129,33 +129,34 @@ void __libc_init_common(KernelArgumentBlock& args) {
* entry in the list has value -1, the last one has value 0.
*/
void __libc_fini(void* array) {
- void** fini_array = reinterpret_cast<void**>(array);
- const size_t minus1 = ~(size_t)0; /* ensure proper sign extension */
+ typedef void (*Dtor)();
+ 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 == NULL || (size_t)fini_array[0] != minus1) {
+ // Sanity check - first entry must be -1.
+ if (array == NULL || fini_array[0] != minus1) {
return;
}
- /* skip over it */
+ // Skip over it.
fini_array += 1;
- /* Count the number of destructors. */
+ // Count the number of destructors.
int count = 0;
while (fini_array[count] != NULL) {
++count;
}
- /* Now call each destructor in reverse order. */
+ // Now call each destructor in reverse order.
while (count > 0) {
- void (*func)() = (void (*)()) fini_array[--count];
+ Dtor dtor = fini_array[--count];
- /* Sanity check, any -1 in the list is ignored */
- if ((size_t)func == minus1) {
+ // Sanity check, any -1 in the list is ignored.
+ if (dtor == minus1) {
continue;
}
- func();
+ dtor();
}
#ifndef LIBC_STATIC