Merge pull request #1783 from RyanDwyer/swaybar-buffer-fixes

Fix buffer issues in swaybar status line
master
emersion 7 years ago committed by GitHub
commit 78b6ac6aa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -113,8 +113,9 @@ bool i3bar_handle_readable(struct status_line *status) {
char *cur = &state->buffer[state->buffer_index]; char *cur = &state->buffer[state->buffer_index];
ssize_t n = read(status->read_fd, cur, ssize_t n = read(status->read_fd, cur,
state->buffer_size - state->buffer_index); state->buffer_size - state->buffer_index);
if (n == 0) { if (n == -1) {
return 0; status_error(status, "[failed to read from status command]");
return false;
} }
if (n == (ssize_t)(state->buffer_size - state->buffer_index)) { 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) { if (!new_buffer) {
free(state->buffer); free(state->buffer);
status_error(status, "[failed to allocate 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; state->buffer = new_buffer;
} }
cur[n] = '\0';
bool redraw = false; bool redraw = false;
while (*cur) { while (*cur) {
if (state->nodes[state->depth] == JSON_NODE_STRING) { if (state->nodes[state->depth] == JSON_NODE_STRING) {

Loading…
Cancel
Save