From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Sat, 16 Mar 2024 18:03:06 +0000 (+0100) Subject: treewide: properly clear the buffer X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=343918dee06ff76beb49b31ef4861832629011a4;p=proto%2Flabwc.git treewide: properly clear the buffer Before this patch, the OSD would repeat the last buffer content in case the new buffer content would be empty. This was mostly happening for the `title` OSD field that is intended to be empty when it matches the app_id / WM_CLASS of the application. Due to only buffer.len being reset but its internal allocations being untouched, buffer.buf would still carry the old data. This patch fixes it by also overwriting the first byte in the buffer allocation with '\0' via the new `buf_clear()` function. Do the same for buf_expand_shell_variables() although that one should have been fine before as it always writes new data to the buffer. --- diff --git a/src/common/buf.c b/src/common/buf.c index f6667418..f6bde97f 100644 --- a/src/common/buf.c +++ b/src/common/buf.c @@ -52,7 +52,7 @@ buf_expand_shell_variables(struct buf *s) for (int i = 0 ; i < s->len ; i++) { if (s->buf[i] == '$' && isvalid(s->buf[i+1])) { /* expand environment variable */ - environment_variable.len = 0; + buf_clear(&environment_variable); buf_add(&environment_variable, s->buf + i + 1); char *p = environment_variable.buf; while (isvalid(*p)) { diff --git a/src/osd.c b/src/osd.c index 69feb4c8..ca53cec8 100644 --- a/src/osd.c +++ b/src/osd.c @@ -286,7 +286,7 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h, int nr_fields = wl_list_length(&rc.window_switcher.fields); struct window_switcher_field *field; wl_list_for_each(field, &rc.window_switcher.fields, link) { - buf.len = 0; + buf_clear(&buf); cairo_move_to(cairo, x, y + theme->osd_window_switcher_item_padding_y + theme->osd_window_switcher_item_active_border_width);