[PATCH] More portability fixes

Denys Vlasenko vda.linux at googlemail.com
Sat Sep 12 12:50:06 UTC 2009


On Saturday 12 September 2009 07:25, Dan Fandrich wrote:
> Attached are some more patches in the same vein as my last batch,
> primarily to improve portability.  A few of the patches do increase the code
> size slightly,

It is almost never acceptable for busybox to increase code size
with no benefit in the behavior whatsoever.

This:

-               const char *args[] = { "sh", "-c", opt_connect, NULL };
+               const char *args[] = { "sh", "-c", NULL, NULL };
+               args[2] = opt_connect;

results in

   text    data     bss     dec     hex filename
 824278     458    6956  831692   cb0cc busybox_old
 824292     458    6956  831706   cb0da busybox_unstripped

It can be done better:

-               const char *args[] = { "sh", "-c", opt_connect, NULL };
+               const char *args[4];
+               args[0] = "sh";
+               args[1] = "-c";
+               args[2] = opt_connect;
+               args[3] = NULL;


From the first patch, I am applying everything except these two parts:
(1) here alloca would probably work better (won't increase code):

-       char *argv[ap->exec_argc + 1];
+       char **argv = malloc(sizeof(char*) * (ap->exec_argc + 1));
        for (i = 0; i < ap->exec_argc; i++)
                argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName);
        argv[i] = NULL; /* terminate the list */
@@ -288,6 +288,7 @@ ACTF(exec)
        i = 0;
        while (argv[i])
                free(argv[i++]);
+       free(argv);

and this should not be necessary:

-               free(ret);
+               if (ret) {
+                       free(ret);
+               }

Is there really are broken platforms where free(NULL) is unsafe?


> busybox-space.diff

function                                             old     new   delta
find_function_slot                                     -      47     +47
run_list                                            2508    2491     -17
find_function                                         40       8     -32
builtin_unset                                        227     165     -62

Applied, thanks!

--
vda


More information about the busybox mailing list