From bac65078a28323ced0d25d7decea783c157028d4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 9 Apr 2018 17:25:39 +1000 Subject: [PATCH 1/2] Fix buffer issues in swaybar status line. --- swaybar/i3bar.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index ed134a016..6f67ba3aa 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c @@ -125,9 +125,12 @@ bool i3bar_handle_readable(struct status_line *status) { status_error(status, "[failed to allocate buffer]"); return -1; } + 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) { From ac3be29517ead2188e43ab1bdb8de31f17633c94 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 9 Apr 2018 08:07:54 -0400 Subject: [PATCH 2/2] Fix some more bugs --- swaybar/i3bar.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 6f67ba3aa..923ad7558 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,7 +124,7 @@ 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;