From 0753196a1a7f01e91f59cec0cf2a800062532f37 Mon Sep 17 00:00:00 2001 From: domsson Date: Fri, 25 Sep 2020 22:02:08 +0900 Subject: [PATCH] Fixed #36 (compile warnings) by putting in a 0 check --- cfg/succaderc.1 | 1 + src/succade.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cfg/succaderc.1 b/cfg/succaderc.1 index bd5d6ba..ea5b494 100644 --- a/cfg/succaderc.1 +++ b/cfg/succaderc.1 @@ -2,6 +2,7 @@ name = "testbar" blocks = "desktop | user | date time" height = 24 +areas = 16 foreground = "#000000" background = "#ce7942" underline = true diff --git a/src/succade.c b/src/succade.c index e19635e..7d69f00 100644 --- a/src/succade.c +++ b/src/succade.c @@ -469,7 +469,10 @@ static char *barstr(const state_s *state) // Short blocks like temperature, volume or battery, will usually use // something in the range of 130 to 200 byte. So let's go with 256 byte. size_t bar_str_len = 256 * num_blocks; // TODO hardcoded value - char *bar_str = malloc(bar_str_len); + + // We need to allocate at least 2 byte, so that even if num_blocks is 0, + // we have space for the '\0\n' sequence and can return a valid string. + char *bar_str = malloc(bar_str_len > 0 ? bar_str_len : 2); bar_str[0] = '\0'; char align[5];