diff options
author | emersion <contact@emersion.fr> | 2018-04-09 08:10:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-09 08:10:51 -0400 |
commit | 78b6ac6aa1377948182a3f7e4bc108bd87d25e0e (patch) | |
tree | a5c038206a9244cb7098f3199c834cba2570b965 /swaybar/i3bar.c | |
parent | 07b6be62144f84539b97ce9d41e9a6c5792deb54 (diff) | |
parent | ac3be29517ead2188e43ab1bdb8de31f17633c94 (diff) |
Merge pull request #1783 from RyanDwyer/swaybar-buffer-fixes
Fix buffer issues in swaybar status line
Diffstat (limited to 'swaybar/i3bar.c')
-rw-r--r-- | swaybar/i3bar.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index ed134a01..923ad755 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c @@ -113,8 +113,9 @@ bool i3bar_handle_readable(struct status_line *status) { char *cur = &state->buffer[state->buffer_index]; ssize_t n = read(status->read_fd, cur, state->buffer_size - state->buffer_index); - if (n == 0) { - return 0; + if (n == -1) { + status_error(status, "[failed to read from status command]"); + return false; } if (n == (ssize_t)(state->buffer_size - state->buffer_index)) { @@ -123,11 +124,14 @@ bool i3bar_handle_readable(struct status_line *status) { if (!new_buffer) { free(state->buffer); status_error(status, "[failed to allocate buffer]"); - return -1; + return true; } + state->current_node += new_buffer - state->buffer; + cur += new_buffer - state->buffer; state->buffer = new_buffer; } + cur[n] = '\0'; bool redraw = false; while (*cur) { if (state->nodes[state->depth] == JSON_NODE_STRING) { |