]> git.mdlowis.com Git - proto/labwc.git/commitdiff
buf.c: correctly handle unset environment variables
authorJohan Malm <jgm323@gmail.com>
Mon, 11 Oct 2021 21:28:06 +0000 (22:28 +0100)
committerJohan Malm <jgm323@gmail.com>
Mon, 11 Oct 2021 21:28:17 +0000 (22:28 +0100)
src/common/buf.c

index abc2b877ecf31fd5ca232776ab5da4440c6a9545..010709084350cc74f2366ffa8c824b8fa1f5cda5 100644 (file)
@@ -20,10 +20,9 @@ buf_expand_shell_variables(struct buf *s)
                        }
                        *p = '\0';
                        p = getenv(environment_variable.buf);
-                       if (!p) {
-                               goto out;
+                       if (p) {
+                               buf_add(&new, p);
                        }
-                       buf_add(&new, p);
                        i += strlen(environment_variable.buf);
                } else if (s->buf[i] == '~') {
                        /* expand tilde */
@@ -38,7 +37,6 @@ buf_expand_shell_variables(struct buf *s)
                        new.buf[new.len] = '\0';
                }
        }
-out:
        free(environment_variable.buf);
        free(s->buf);
        s->buf = new.buf;