From 42946ec113e8ae6d6bc114dbd90e9721f464abfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 28 Sep 2020 21:14:50 +0200 Subject: [PATCH] Introduce ARRAYSIZE --- Macros.h | 4 ++++ Settings.c | 2 +- linux/LinuxCRT.c | 2 +- linux/Platform.c | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Macros.h b/Macros.h index ef4e8908..de674eda 100644 --- a/Macros.h +++ b/Macros.h @@ -13,6 +13,10 @@ #define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) #endif +#ifndef ARRAYSIZE +#define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + #ifdef __GNUC__ // defined by GCC and Clang #define ATTR_FORMAT(type, index, check) __attribute__((format (type, index, check))) diff --git a/Settings.c b/Settings.c index 0aac4796..1cfd0061 100644 --- a/Settings.c +++ b/Settings.c @@ -20,7 +20,7 @@ in the source distribution for its full text. void Settings_delete(Settings* this) { free(this->filename); free(this->fields); - for (unsigned int i = 0; i < (sizeof(this->columns)/sizeof(MeterColumnSettings)); i++) { + for (unsigned int i = 0; i < ARRAYSIZE(this->columns); i++) { String_freeArray(this->columns[i].names); free(this->columns[i].modes); } diff --git a/linux/LinuxCRT.c b/linux/LinuxCRT.c index 2679d4f6..7adb154d 100644 --- a/linux/LinuxCRT.c +++ b/linux/LinuxCRT.c @@ -22,7 +22,7 @@ void CRT_handleSIGSEGV(int sgn) { #ifdef __linux fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); #ifdef HAVE_EXECINFO_H - size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); + size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray)); fprintf(stderr, "\n Please include in your report the following backtrace: \n"); backtrace_symbols_fd(backtraceArray, size, 2); fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); diff --git a/linux/Platform.c b/linux/Platform.c index 78313b2d..2d325864 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -79,7 +79,7 @@ const SignalItem Platform_signals[] = { { .name = "31 SIGSYS", .number = 31 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); static Htop_Reaction Platform_actionSetIOPriority(State* st) { Panel* panel = st->panel;