aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c26
-rw-r--r--shell/shell_common.c4
2 files changed, 7 insertions, 23 deletions
diff --git a/shell/hush.c b/shell/hush.c
index fc6db316e..30add72f0 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1478,8 +1478,6 @@ typedef struct save_arg_t {
static void save_and_replace_G_args(save_arg_t *sv, char **argv)
{
- int n;
-
sv->sv_argv0 = argv[0];
sv->sv_g_argv = G.global_argv;
sv->sv_g_argc = G.global_argc;
@@ -1489,10 +1487,7 @@ static void save_and_replace_G_args(save_arg_t *sv, char **argv)
G.global_argv = argv;
IF_HUSH_SET(G.global_args_malloced = 0;)
- n = 1;
- while (*++argv)
- n++;
- G.global_argc = n;
+ G.global_argc = 1 + string_array_len(argv + 1);
}
static void restore_G_args(save_arg_t *sv, char **argv)
@@ -6809,13 +6804,11 @@ static void exec_function(char ***to_free,
char **argv)
{
# if BB_MMU
- int n = 1;
+ int n;
argv[0] = G.global_argv[0];
G.global_argv = argv;
- while (*++argv)
- n++;
- G.global_argc = n;
+ G.global_argc = n = 1 + string_array_len(argv + 1);
/* On MMU, funcp->body is always non-NULL */
n = run_list(funcp->body);
fflush_all();
@@ -8811,12 +8804,8 @@ static int FAST_FUNC builtin_true(char **argv UNUSED_PARAM)
#if ENABLE_HUSH_TEST || ENABLE_HUSH_ECHO || ENABLE_HUSH_PRINTF || ENABLE_HUSH_KILL
static int run_applet_main(char **argv, int (*applet_main_func)(int argc, char **argv))
{
- int argc = 0;
- while (*argv) {
- argc++;
- argv++;
- }
- return applet_main_func(argc, argv - argc);
+ int argc = string_array_len(argv);
+ return applet_main_func(argc, argv);
}
#endif
#if ENABLE_HUSH_TEST || BASH_TEST2
@@ -9363,10 +9352,7 @@ static int FAST_FUNC builtin_set(char **argv)
/* This realloc's G.global_argv */
G.global_argv = pp = add_strings_to_strings(g_argv, argv, /*dup:*/ 1);
- n = 1;
- while (*++pp)
- n++;
- G.global_argc = n;
+ G.global_argc = 1 + string_array_len(pp + 1);
return EXIT_SUCCESS;
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 03b7d0b75..bf56f3d78 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -405,9 +405,7 @@ shell_builtin_ulimit(char **argv)
*/
GETOPT_RESET();
- argc = 1;
- while (argv[argc])
- argc++;
+ argc = string_array_len(argv);
opts = 0;
while (1) {