summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-09-28 21:14:50 +0200
committerChristian Göttsche <cgzones@googlemail.com>2020-10-03 19:05:40 +0200
commit42946ec113e8ae6d6bc114dbd90e9721f464abfb (patch)
tree3b30fc9a612905cd4e2b868804ac81cd2c90b403
parentb82a13c6ba48eb8711071342bec80798aca5de1c (diff)
Introduce ARRAYSIZE
-rw-r--r--Macros.h4
-rw-r--r--Settings.c2
-rw-r--r--linux/LinuxCRT.c2
-rw-r--r--linux/Platform.c2
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;

© 2014-2024 Faster IT GmbH | imprint | privacy policy