From: Denys Vlasenko Date: Mon, 9 Jan 2017 06:57:38 +0000 (+0100) Subject: hush: global_args_malloced is used only if set builtin is enabled X-Git-Tag: 1_27_0~262 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4e4f88e569e6e32669c856a86c60bb3fc104d588;p=oweals%2Fbusybox.git hush: global_args_malloced is used only if set builtin is enabled function old new delta run_pipe 1623 1635 +12 builtin_source 210 222 +12 save_and_replace_G_args 70 60 -10 builtin_shift 132 94 -38 restore_G_args 98 - -98 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 2/2 up/down: 24/-146) Total: -122 bytes Signed-off-by: Denys Vlasenko --- diff --git a/shell/hush.c b/shell/hush.c index faff86d88..c69e4ec8a 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -853,8 +853,13 @@ struct globals { smallint exiting; /* used to prevent EXIT trap recursion */ /* These four support $?, $#, and $1 */ smalluint last_exitcode; +#if ENABLE_HUSH_SET /* are global_argv and global_argv[1..n] malloced? (note: not [0]) */ smalluint global_args_malloced; +# define G_global_args_malloced (G.global_args_malloced) +#else +# define G_global_args_malloced 0 +#endif /* how many non-NULL argv's we have. NB: $# + 1 */ int global_argc; char **global_argv; @@ -893,7 +898,7 @@ struct globals { unsigned special_sig_mask; #if ENABLE_HUSH_JOB unsigned fatal_sig_mask; -# define G_fatal_sig_mask G.fatal_sig_mask +# define G_fatal_sig_mask (G.fatal_sig_mask) #else # define G_fatal_sig_mask 0 #endif @@ -1476,7 +1481,7 @@ typedef struct save_arg_t { char *sv_argv0; char **sv_g_argv; int sv_g_argc; - smallint sv_g_malloced; + IF_HUSH_SET(smallint sv_g_malloced;) } save_arg_t; static void save_and_replace_G_args(save_arg_t *sv, char **argv) @@ -1486,11 +1491,11 @@ static void save_and_replace_G_args(save_arg_t *sv, char **argv) sv->sv_argv0 = argv[0]; sv->sv_g_argv = G.global_argv; sv->sv_g_argc = G.global_argc; - sv->sv_g_malloced = G.global_args_malloced; + IF_HUSH_SET(sv->sv_g_malloced = G.global_args_malloced;) argv[0] = G.global_argv[0]; /* retain $0 */ G.global_argv = argv; - G.global_args_malloced = 0; + IF_HUSH_SET(G.global_args_malloced = 0;) n = 1; while (*++argv) @@ -1500,19 +1505,19 @@ static void save_and_replace_G_args(save_arg_t *sv, char **argv) static void restore_G_args(save_arg_t *sv, char **argv) { - char **pp; - +#if ENABLE_HUSH_SET if (G.global_args_malloced) { /* someone ran "set -- arg1 arg2 ...", undo */ - pp = G.global_argv; + char **pp = G.global_argv; while (*++pp) /* note: does not free $0 */ free(*pp); free(G.global_argv); } +#endif argv[0] = sv->sv_argv0; G.global_argv = sv->sv_g_argv; G.global_argc = sv->sv_g_argc; - G.global_args_malloced = sv->sv_g_malloced; + IF_HUSH_SET(G.global_args_malloced = sv->sv_g_malloced;) } @@ -9213,7 +9218,7 @@ static int FAST_FUNC builtin_shift(char **argv) n = atoi(argv[0]); } if (n >= 0 && n < G.global_argc) { - if (G.global_args_malloced) { + if (G_global_args_malloced) { int m = 1; while (m <= n) free(G.global_argv[m++]);