From 44e09392c72cbd72c1e5b4ec3dea71f9b38e13c8 Mon Sep 17 00:00:00 2001 From: Markus Wichmann Date: Sun, 19 Jan 2020 11:58:51 +0100 Subject: [PATCH] Make libc_exit_fini() easier to read. The previous version did have a maze of parentheses here. But the actual logic of the function is not to iterate over some numbers that happen to be convertible to pointers, but rather to iterate over an array of function pointers. So let us use pointer arithmetic correctly. --- src/exit/exit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/exit/exit.c b/src/exit/exit.c index a6869b37..e02ba2be 100644 --- a/src/exit/exit.c +++ b/src/exit/exit.c @@ -16,9 +16,9 @@ extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_ static void libc_exit_fini(void) { - uintptr_t a = (uintptr_t)&__fini_array_end; - for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)())) - (*(void (**)())(a-sizeof(void(*)())))(); + void (*const *a)() = &__fini_array_end; + while (a > &__fini_array_start) + (*--a)(); _fini(); } -- 2.17.1