From f42e1895d41187cfca00e9cd61aeaeabbb830fbf Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 5 May 2026 19:11:34 +0100 Subject: [PATCH] buf.c: fix -fanalyze warning ../src/common/buf.c:61:28: error: write to string literal [-Werror=analyzer-write-to-string-literal] 61 | *p = '\0'; | ~~~^~~~~~ --- src/common/buf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/common/buf.c b/src/common/buf.c index c141b62e..2a68b734 100644 --- a/src/common/buf.c +++ b/src/common/buf.c @@ -53,15 +53,14 @@ buf_expand_shell_variables(struct buf *s) if (s->data[i] == '$' && isvalid(s->data[i+1])) { /* expand environment variable */ buf_clear(&environment_variable); - buf_add(&environment_variable, s->data + i + 1); - char *p = environment_variable.data; - while (isvalid(*p)) { - ++p; + int len = 0; + while (isvalid(s->data[i + 1 + len])) { + buf_add_char(&environment_variable, s->data[i + 1 + len]); + ++len; } - *p = '\0'; - i += strlen(environment_variable.data); + i += len; strip_curly_braces(environment_variable.data); - p = getenv(environment_variable.data); + char *p = getenv(environment_variable.data); if (p) { buf_add(&tmp, p); }