From 51ead9d8b68a7b65010da8c943f5e8264ded01b9 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 8 Apr 2024 15:05:44 +0200 Subject: Explicit memory initialization when reading status file --- linux/LinuxProcessTable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessTable.c b/linux/LinuxProcessTable.c index f8adf9ad..49093219 100644 --- a/linux/LinuxProcessTable.c +++ b/linux/LinuxProcessTable.c @@ -417,7 +417,7 @@ static bool LinuxProcessTable_readStatusFile(Process* process, openat_arg_t proc if (!statusfile) return false; - char buffer[PROC_LINE_LENGTH + 1]; + char buffer[PROC_LINE_LENGTH + 1] = {0}; while (fgets(buffer, sizeof(buffer), statusfile)) { -- cgit v1.2.3 From 9cc1c5ea15cc7f7fa6ebcdee151df9da56e95009 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 8 Apr 2024 15:06:59 +0200 Subject: Reserve full function array to make the GCC14 static code analyzer happy Only happens with LTO, -fanalyzer, and -fsanitize=address,leak --- FunctionBar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FunctionBar.c b/FunctionBar.c index 08500373..0e4fe761 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -30,7 +30,7 @@ static const int FunctionBar_EnterEscEvents[] = {13, 27}; static int currentLen = 0; FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) { - const char* functions[] = {enter, esc, NULL}; + const char* functions[16] = {enter, esc, NULL}; return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents); } -- cgit v1.2.3 From 0a1db8a770128dec1bb78e5e5217c169a797d0bc Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Thu, 18 Apr 2024 10:12:00 +0200 Subject: Avoid magic numbers for the size of FunctionBar lists --- FunctionBar.c | 14 +++++++------- FunctionBar.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/FunctionBar.c b/FunctionBar.c index 0e4fe761..af4142e9 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -30,25 +30,25 @@ static const int FunctionBar_EnterEscEvents[] = {13, 27}; static int currentLen = 0; FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) { - const char* functions[16] = {enter, esc, NULL}; + const char* functions[FUNCTIONBAR_MAXEVENTS + 1] = {enter, esc, NULL}; return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents); } FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events) { FunctionBar* this = xCalloc(1, sizeof(FunctionBar)); - this->functions = xCalloc(16, sizeof(char*)); + this->functions = xCalloc(FUNCTIONBAR_MAXEVENTS + 1, sizeof(char*)); if (!functions) { functions = FunctionBar_FLabels; } - for (int i = 0; i < 15 && functions[i]; i++) { + for (int i = 0; i < FUNCTIONBAR_MAXEVENTS && functions[i]; i++) { this->functions[i] = xStrdup(functions[i]); } if (keys && events) { this->staticData = false; - this->keys.keys = xCalloc(15, sizeof(char*)); - this->events = xCalloc(15, sizeof(int)); + this->keys.keys = xCalloc(FUNCTIONBAR_MAXEVENTS, sizeof(char*)); + this->events = xCalloc(FUNCTIONBAR_MAXEVENTS, sizeof(int)); int i = 0; - while (i < 15 && functions[i]) { + while (i < FUNCTIONBAR_MAXEVENTS && functions[i]) { this->keys.keys[i] = xStrdup(keys[i]); this->events[i] = events[i]; i++; @@ -64,7 +64,7 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke } void FunctionBar_delete(FunctionBar* this) { - for (int i = 0; i < 15 && this->functions[i]; i++) { + for (int i = 0; i < FUNCTIONBAR_MAXEVENTS && this->functions[i]; i++) { free(this->functions[i]); } free(this->functions); diff --git a/FunctionBar.h b/FunctionBar.h index f01a5ef5..06d9c6c8 100644 --- a/FunctionBar.h +++ b/FunctionBar.h @@ -21,6 +21,8 @@ typedef struct FunctionBar_ { bool staticData; } FunctionBar; +#define FUNCTIONBAR_MAXEVENTS 15 + FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc); FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events); -- cgit v1.2.3