hush: smaller code to set o_string to ""
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 18 Jul 2018 13:48:53 +0000 (15:48 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 18 Jul 2018 13:50:04 +0000 (15:50 +0200)
function                                             old     new   delta
encode_then_expand_vararg                            399     398      -1
parse_stream                                        2753    2748      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c

index 7da8f334c30894c397be5ffbeb8ade3a141beafe..534fabbd0beeffe43d899e8b200c303172b32d87 100644 (file)
@@ -4997,8 +4997,7 @@ static struct pipe *parse_stream(char **pstring,
        /* If very first arg is "" or '', ctx.word.data may end up NULL.
         * Preventing this:
         */
-       o_addchr(&ctx.word, '\0');
-       ctx.word.length = 0;
+       ctx.word.data = xzalloc(1); /* start as "", not as NULL */
 
        /* We used to separate words on $IFS here. This was wrong.
         * $IFS is used only for word splitting when $var is expanded,
@@ -5795,8 +5794,7 @@ static char *encode_then_expand_vararg(const char *str, int handle_squotes, int
         */
 
        setup_string_in_str(&input, str);
-       o_addchr(&dest, '\0');
-       dest.length = 0;
+       dest.data = xzalloc(1); /* start as "", not as NULL */
        exp_str = NULL;
 
        for (;;) {