Skip to content

Commit

Permalink
Fixed #36 (compile warnings) by putting in a 0 check
Browse files Browse the repository at this point in the history
  • Loading branch information
domsson committed Sep 25, 2020
1 parent 948f560 commit 0753196
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions cfg/succaderc.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "testbar"
blocks = "desktop | user | date time"
height = 24
areas = 16
foreground = "#000000"
background = "#ce7942"
underline = true
Expand Down
5 changes: 4 additions & 1 deletion src/succade.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 0753196

Please sign in to comment.