diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-09-28 21:14:50 +0200 |
---|---|---|
committer | Christian Göttsche <cgzones@googlemail.com> | 2020-10-03 19:05:40 +0200 |
commit | 42946ec113e8ae6d6bc114dbd90e9721f464abfb (patch) | |
tree | 3b30fc9a612905cd4e2b868804ac81cd2c90b403 | |
parent | b82a13c6ba48eb8711071342bec80798aca5de1c (diff) |
Introduce ARRAYSIZE
-rw-r--r-- | Macros.h | 4 | ||||
-rw-r--r-- | Settings.c | 2 | ||||
-rw-r--r-- | linux/LinuxCRT.c | 2 | ||||
-rw-r--r-- | linux/Platform.c | 2 |
4 files changed, 7 insertions, 3 deletions
@@ -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))) @@ -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; |