*: use llist_pop for traverse-and-free list operation
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 15 Jun 2008 05:40:56 +0000 (05:40 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 15 Jun 2008 05:40:56 +0000 (05:40 -0000)
function                                             old     new   delta
append_file_list_to_list                             109     111      +2
udhcpc_main                                         2414    2413      -1
run_parts_main                                       325     324      -1
od_main                                             2324    2323      -1
getopt_main                                          709     707      -2
env_main                                             253     251      -2
sed_main                                             659     656      -3
ps_main                                              522     519      -3
traceroute_main                                     3960    3954      -6
sort_main                                            844     838      -6
diff_main                                            866     858      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/10 up/down: 2/-33)            Total: -31 bytes

14 files changed:
archival/tar.c
coreutils/env.c
coreutils/od_bloaty.c
coreutils/sort.c
debianutils/run_parts.c
editors/diff.c
editors/sed.c
findutils/xargs.c
libbb/getopt32.c
networking/traceroute.c
networking/udhcp/dhcpc.c
networking/wget.c
procps/ps.c
util-linux/getopt.c

index 64a4e35bee8fa2671f1cec8a84bc44993f94baf1..0162e06239bce67a9ef789f5cf2d093bd1195279 100644 (file)
@@ -659,16 +659,11 @@ int writeTarFile(int tar_fd, int verboseFlag,
 static llist_t *append_file_list_to_list(llist_t *list)
 {
        FILE *src_stream;
-       llist_t *cur = list;
-       llist_t *tmp;
        char *line;
        llist_t *newlist = NULL;
 
-       while (cur) {
-               src_stream = xfopen(cur->data, "r");
-               tmp = cur;
-               cur = cur->link;
-               free(tmp);
+       while (list) {
+               src_stream = xfopen(llist_pop(&list), "r");
                while ((line = xmalloc_fgetline(src_stream)) != NULL) {
                        /* kill trailing '/' unless the string is just "/" */
                        char *cp = last_char_is(line, '/');
index e21740d9858794336cc76bd6c9cadc148201c8fa..8d8753e8b6e15156a7099abaa520db7ce764a2c9 100644 (file)
@@ -62,8 +62,7 @@ int env_main(int argc ATTRIBUTE_UNUSED, char **argv)
                environ = cleanenv;
        } else {
                while (unset_env) {
-                       unsetenv(unset_env->data);
-                       unset_env = unset_env->link;
+                       unsetenv(llist_pop(&unset_env));
                }
        }
 
index 5e2287534a7db38991417195c0c364fd1db740d2..ce963db8afdfa8e52db6434ea8c7abec4517a549 100644 (file)
@@ -1281,8 +1281,7 @@ int od_main(int argc, char **argv)
        if (opt & OPT_o) decode_format_string("o2");
        //if (opt & OPT_t)...
        while (lst_t) {
-               decode_format_string(lst_t->data);
-               lst_t = lst_t->link;
+               decode_format_string(llist_pop(&lst_t));
        }
        if (opt & OPT_v) verbose = 1;
        if (opt & OPT_x) decode_format_string("x2");
index 12b463a6d0f1db1f345befbd56044996d3e67657..1f531fb76309cc305e82b8e2a540840f3f836d28 100644 (file)
@@ -314,7 +314,7 @@ int sort_main(int argc ATTRIBUTE_UNUSED, char **argv)
                        0
                };
                struct sort_key *key = add_key();
-               char *str_k = lst_k->data;
+               char *str_k = llist_pop(&lst_k);
                const char *temp2;
 
                i = 0; /* i==0 before comma, 1 after (-k3,6) */
@@ -344,8 +344,6 @@ int sort_main(int argc ATTRIBUTE_UNUSED, char **argv)
                                str_k++;
                        }
                }
-               /* leaking lst_k... */
-               lst_k = lst_k->link;
        }
 #endif
        /* global b strips leading and trailing spaces */
index 47eda8cf6541b3a8c75edcb7a44389e8a1d655f8..c9b0907172c15bd72d43d8e0c8db5c80c5203556 100644 (file)
@@ -42,7 +42,7 @@ struct globals {
 #define cur   (G.cur  )
 #define cmd   (G.cmd  )
 
-enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(struct globals)) / sizeof(cmd[0]) };
+enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 };
 
 enum {
        OPT_r = (1 << 0),
@@ -130,9 +130,7 @@ int run_parts_main(int argc ATTRIBUTE_UNUSED, char **argv)
 
        n = 1;
        while (arg_list && n < NUM_CMD) {
-               cmd[n] = arg_list->data;
-               arg_list = arg_list->link;
-               n++;
+               cmd[n++] = llist_pop(&arg_list);
        }
        /* cmd[n] = NULL; - is already zeroed out */
 
index 4e51f6f76886f5a1a13ac4b772d6557af391c57b..26f352780ba1d0ef342d66fb5d94d5ec00508d1b 100644 (file)
@@ -1289,14 +1289,9 @@ int diff_main(int argc ATTRIBUTE_UNUSED, char **argv)
        while (L_arg) {
                if (label1 && label2)
                        bb_show_usage();
-               if (!label1)
-                       label1 = L_arg->data;
-               else { /* then label2 is NULL */
+               if (label1) /* then label2 is NULL */
                        label2 = label1;
-                       label1 = L_arg->data;
-               }
-               /* we leak L_arg here... */
-               L_arg = L_arg->link;
+               label1 = llist_pop(&L_arg);
        }
 
        /*
index 817840dc0180101ea722bc557853b9a6a4740141..bf01fc6308a8c1b850e1f58aeb1d16a7938112a1 100644 (file)
@@ -1267,21 +1267,17 @@ int sed_main(int argc ATTRIBUTE_UNUSED, char **argv)
        if (opt & 0x2) G.regex_type |= REG_EXTENDED; // -r
        //if (opt & 0x4) G.be_quiet++; // -n
        while (opt_e) { // -e
-               add_cmd_block(opt_e->data);
-               opt_e = opt_e->link;
-               /* we leak opt_e here... */
+               add_cmd_block(llist_pop(&opt_e));
        }
        while (opt_f) { // -f
                char *line;
                FILE *cmdfile;
-               cmdfile = xfopen(opt_f->data, "r");
+               cmdfile = xfopen(llist_pop(&opt_f), "r");
                while ((line = xmalloc_fgetline(cmdfile)) != NULL) {
                        add_cmd(line);
                        free(line);
                }
                fclose(cmdfile);
-               opt_f = opt_f->link;
-               /* we leak opt_f here... */
        }
        /* if we didn't get a pattern from -e or -f, use argv[0] */
        if (!(opt & 0x18)) {
index 352f7e64c72fad38bd5873cff3da37b1ff80e2dd..3322e9ebdfe9d28feae49e51fbb6a90d3e4ca966 100644 (file)
@@ -502,7 +502,7 @@ int xargs_main(int argc, char **argv)
                if (child_error > 0 && child_error != 123) {
                        break;
                }
-       }
+       } /* while */
        if (ENABLE_FEATURE_CLEAN_UP)
                free(max_chars);
        return child_error;
index 4b5a7d2085a9b9087e4b6096928fe7fed4b533e2..86c33483baa4e3b505d7f0ec9fa98d4dfef8da29 100644 (file)
@@ -137,7 +137,7 @@ const char *opt_complementary
         opt_complementary = "vv:b::b-c:c-b";
         f = getopt32(argv, "vb:c", &my_b, &verbose_level);
         if (f & 2)       // -c after -b unsets -b flag
-                while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; }
+                while (my_b) dosomething_with(llist_pop(&my_b));
         if (my_b)        // but llist is stored if -b is specified
                 free_llist(my_b);
         if (verbose_level) printf("verbose level is %d\n", verbose_level);
index e9df27559973618acfe1ea71ad157bd4baa859a1..6a5373469cf04da683bbc8a5dcc10017794dacb4 100644 (file)
@@ -1001,17 +1001,11 @@ int traceroute_main(int argc, char **argv)
 
 #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
        if (source_route_list) {
-               llist_t *l_sr;
-
-               l_sr = source_route_list;
-               while (l_sr) {
+               while (source_route_list) {
                        if (lsrr >= NGATEWAYS)
                                bb_error_msg_and_die("no more than %d gateways", NGATEWAYS);
-                       getaddr(gwlist + lsrr, l_sr->data);
+                       getaddr(gwlist + lsrr, llist_pop(&source_route_list));
                        ++lsrr;
-                       l_sr = l_sr->link;
-                       free(source_route_list);
-                       source_route_list = l_sr;
                }
                optlen = (lsrr + 1) * sizeof(gwlist[0]);
        }
index 655d39fd2f322d2a71a64cf848d9e7522a679504..5eb1ed5fdd06766134ebbcc2a33efb1b8b781434 100644 (file)
@@ -259,12 +259,11 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
        if (opt & OPT_o)
                client_config.no_default_options = 1;
        while (list_O) {
-               int n = index_in_strings(dhcp_option_strings, list_O->data);
+               int n = index_in_strings(dhcp_option_strings, llist_pop(&list_O));
                if (n < 0)
                        bb_error_msg_and_die("unknown option '%s'", list_O->data);
                n = dhcp_options[n].code;
                client_config.opt_mask[n >> 3] |= 1 << (n & 7);
-               list_O = list_O->link;
        }
 
        if (read_interface(client_config.interface, &client_config.ifindex,
index 84ee1ca3eb9f82bdcd2781b1501072a1e87963d9..7198197dd4d013c40f057cb207ea838271a308cc 100644 (file)
@@ -469,8 +469,7 @@ int wget_main(int argc ATTRIBUTE_UNUSED, char **argv)
                }
                extra_headers = cp = xmalloc(size);
                while (headers_llist) {
-                       cp += sprintf(cp, "%s\r\n", headers_llist->data);
-                       headers_llist = headers_llist->link;
+                       cp += sprintf(cp, "%s\r\n", (char*)llist_pop(&headers_llist));
                }
        }
 #endif
index 1ab3973e721f15ff0022da98464911817d2e2a79..cfca851cf93da54ff96f3aa92c33449c54dfacc4 100644 (file)
@@ -443,8 +443,7 @@ int ps_main(int argc ATTRIBUTE_UNUSED, char **argv)
        USE_SELINUX(opt =) getopt32(argv, "Zo:aAdefl", &opt_o);
        if (opt_o) {
                do {
-                       parse_o(opt_o->data);
-                       opt_o = opt_o->link;
+                       parse_o(llist_pop(&opt_o));
                } while (opt_o);
        } else {
                /* Below: parse_o() needs char*, NOT const char*... */
index 31790d2a7b67e9ee7beaa2a2f0ac6011c2e22d4c..e3b4ca6259142089682995b162dfcfed76dfb39d 100644 (file)
@@ -329,8 +329,7 @@ int getopt_main(int argc, char **argv)
                                        &optstr, &name, &s_arg, &l_arg);
        /* Effectuate the read options for the applet itself */
        while (l_arg) {
-               long_options = add_long_options(long_options, l_arg->data);
-               l_arg = l_arg->link;
+               long_options = add_long_options(long_options, llist_pop(&l_arg));
        }
 #endif