aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-09 07:57:38 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-09 07:57:38 +0100
commit4e4f88e569e6e32669c856a86c60bb3fc104d588 (patch)
treeaaea9a844eeb25c37a002c7247d9517bcb16764d
parentcc2fd5a9867519da24672fae560e511a4a6940e7 (diff)
downloadbusybox-w32-4e4f88e569e6e32669c856a86c60bb3fc104d588.tar.gz
busybox-w32-4e4f88e569e6e32669c856a86c60bb3fc104d588.tar.bz2
busybox-w32-4e4f88e569e6e32669c856a86c60bb3fc104d588.zip
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 <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c23
1 files changed, 14 insertions, 9 deletions
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 {
853 smallint exiting; /* used to prevent EXIT trap recursion */ 853 smallint exiting; /* used to prevent EXIT trap recursion */
854 /* These four support $?, $#, and $1 */ 854 /* These four support $?, $#, and $1 */
855 smalluint last_exitcode; 855 smalluint last_exitcode;
856#if ENABLE_HUSH_SET
856 /* are global_argv and global_argv[1..n] malloced? (note: not [0]) */ 857 /* are global_argv and global_argv[1..n] malloced? (note: not [0]) */
857 smalluint global_args_malloced; 858 smalluint global_args_malloced;
859# define G_global_args_malloced (G.global_args_malloced)
860#else
861# define G_global_args_malloced 0
862#endif
858 /* how many non-NULL argv's we have. NB: $# + 1 */ 863 /* how many non-NULL argv's we have. NB: $# + 1 */
859 int global_argc; 864 int global_argc;
860 char **global_argv; 865 char **global_argv;
@@ -893,7 +898,7 @@ struct globals {
893 unsigned special_sig_mask; 898 unsigned special_sig_mask;
894#if ENABLE_HUSH_JOB 899#if ENABLE_HUSH_JOB
895 unsigned fatal_sig_mask; 900 unsigned fatal_sig_mask;
896# define G_fatal_sig_mask G.fatal_sig_mask 901# define G_fatal_sig_mask (G.fatal_sig_mask)
897#else 902#else
898# define G_fatal_sig_mask 0 903# define G_fatal_sig_mask 0
899#endif 904#endif
@@ -1476,7 +1481,7 @@ typedef struct save_arg_t {
1476 char *sv_argv0; 1481 char *sv_argv0;
1477 char **sv_g_argv; 1482 char **sv_g_argv;
1478 int sv_g_argc; 1483 int sv_g_argc;
1479 smallint sv_g_malloced; 1484 IF_HUSH_SET(smallint sv_g_malloced;)
1480} save_arg_t; 1485} save_arg_t;
1481 1486
1482static void save_and_replace_G_args(save_arg_t *sv, char **argv) 1487static 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)
1486 sv->sv_argv0 = argv[0]; 1491 sv->sv_argv0 = argv[0];
1487 sv->sv_g_argv = G.global_argv; 1492 sv->sv_g_argv = G.global_argv;
1488 sv->sv_g_argc = G.global_argc; 1493 sv->sv_g_argc = G.global_argc;
1489 sv->sv_g_malloced = G.global_args_malloced; 1494 IF_HUSH_SET(sv->sv_g_malloced = G.global_args_malloced;)
1490 1495
1491 argv[0] = G.global_argv[0]; /* retain $0 */ 1496 argv[0] = G.global_argv[0]; /* retain $0 */
1492 G.global_argv = argv; 1497 G.global_argv = argv;
1493 G.global_args_malloced = 0; 1498 IF_HUSH_SET(G.global_args_malloced = 0;)
1494 1499
1495 n = 1; 1500 n = 1;
1496 while (*++argv) 1501 while (*++argv)
@@ -1500,19 +1505,19 @@ static void save_and_replace_G_args(save_arg_t *sv, char **argv)
1500 1505
1501static void restore_G_args(save_arg_t *sv, char **argv) 1506static void restore_G_args(save_arg_t *sv, char **argv)
1502{ 1507{
1503 char **pp; 1508#if ENABLE_HUSH_SET
1504
1505 if (G.global_args_malloced) { 1509 if (G.global_args_malloced) {
1506 /* someone ran "set -- arg1 arg2 ...", undo */ 1510 /* someone ran "set -- arg1 arg2 ...", undo */
1507 pp = G.global_argv; 1511 char **pp = G.global_argv;
1508 while (*++pp) /* note: does not free $0 */ 1512 while (*++pp) /* note: does not free $0 */
1509 free(*pp); 1513 free(*pp);
1510 free(G.global_argv); 1514 free(G.global_argv);
1511 } 1515 }
1516#endif
1512 argv[0] = sv->sv_argv0; 1517 argv[0] = sv->sv_argv0;
1513 G.global_argv = sv->sv_g_argv; 1518 G.global_argv = sv->sv_g_argv;
1514 G.global_argc = sv->sv_g_argc; 1519 G.global_argc = sv->sv_g_argc;
1515 G.global_args_malloced = sv->sv_g_malloced; 1520 IF_HUSH_SET(G.global_args_malloced = sv->sv_g_malloced;)
1516} 1521}
1517 1522
1518 1523
@@ -9213,7 +9218,7 @@ static int FAST_FUNC builtin_shift(char **argv)
9213 n = atoi(argv[0]); 9218 n = atoi(argv[0]);
9214 } 9219 }
9215 if (n >= 0 && n < G.global_argc) { 9220 if (n >= 0 && n < G.global_argc) {
9216 if (G.global_args_malloced) { 9221 if (G_global_args_malloced) {
9217 int m = 1; 9222 int m = 1;
9218 while (m <= n) 9223 while (m <= n)
9219 free(G.global_argv[m++]); 9224 free(G.global_argv[m++]);