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.
This commit is contained in:
Boran Car 2019-03-11 18:38:00 +00:00
parent 3ede5983b9
commit 533c0b24a2

View file

@ -310,9 +310,11 @@ static void log_loaded_themes(list_t *themes) {
const char *sep = ", "; const char *sep = ", ";
size_t sep_len = strlen(sep); size_t sep_len = strlen(sep);
size_t len = 1 - sep_len; size_t len = 1;
for (int i = 0; i < themes->length; ++i) { struct icon_theme *theme = themes->items[0];
struct icon_theme *theme = themes->items[i]; len += strlen(theme->name);
for (int i = 1; i < themes->length; ++i) {
theme = themes->items[i];
len += strlen(theme->name) + sep_len; len += strlen(theme->name) + sep_len;
} }