From 533c0b24a246284ebcb4942ae86d8daa9612553f Mon Sep 17 00:00:00 2001 From: Boran Car Date: Mon, 11 Mar 2019 18:38:00 +0000 Subject: [PATCH] Refactor icon.c to avoid malloc warning The compiler may infer that malloc could be passed a large value based on a "deduced" negative overflow. Simply unroll the first loop pass rather than correct it. This fixes #3868: Compiling on Fedora 29 with hardening fails. --- swaybar/tray/icon.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c index c7ce20b4d..ffb7e2e4f 100644 --- a/swaybar/tray/icon.c +++ b/swaybar/tray/icon.c @@ -310,9 +310,11 @@ static void log_loaded_themes(list_t *themes) { const char *sep = ", "; size_t sep_len = strlen(sep); - size_t len = 1 - sep_len; - for (int i = 0; i < themes->length; ++i) { - struct icon_theme *theme = themes->items[i]; + size_t len = 1; + struct icon_theme *theme = themes->items[0]; + len += strlen(theme->name); + for (int i = 1; i < themes->length; ++i) { + theme = themes->items[i]; len += strlen(theme->name) + sep_len; }