diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-09 18:16:40 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-09 18:16:40 +0200 |
commit | 02859aaeb29fb83167364291f1ce26b54c23803b (patch) | |
tree | 93a30e982b81e3bde6af8800bcd0c8f3f0080f52 | |
parent | e52da5570eb93d6cb2950e55c48bd22edb5a9f18 (diff) | |
download | busybox-w32-02859aaeb29fb83167364291f1ce26b54c23803b.tar.gz busybox-w32-02859aaeb29fb83167364291f1ce26b54c23803b.tar.bz2 busybox-w32-02859aaeb29fb83167364291f1ce26b54c23803b.zip |
use auto_string() where appropriate to kill a few statics
Custom linker script 'busybox_ldscript' found, using it
function old new delta
static.str 4 - -4
static.passwd 4 0 -4
bb_ask 322 311 -11
ether_print 63 47 -16
UNSPEC_print 82 66 -16
INET_sprint 59 38 -21
INET6_sprint 54 30 -24
make_human_readable_str 292 235 -57
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/7 up/down: 0/-153) Total: -153 bytes
text data bss dec hex filename
939880 992 17480 958352 e9f90 busybox_old
939736 992 17456 958184 e9ee8 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/bb_askpass.c | 6 | ||||
-rw-r--r-- | libbb/human_readable.c | 9 | ||||
-rw-r--r-- | miscutils/devfsd.c | 19 | ||||
-rw-r--r-- | networking/interface.c | 24 |
4 files changed, 18 insertions, 40 deletions
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c index 1927ba9e9..c2580b9eb 100644 --- a/libbb/bb_askpass.c +++ b/libbb/bb_askpass.c | |||
@@ -1,7 +1,6 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Ask for a password | 3 | * Ask for a password |
4 | * I use a static buffer in this function. Plan accordingly. | ||
5 | * | 4 | * |
6 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
7 | * | 6 | * |
@@ -23,8 +22,8 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) | |||
23 | { | 22 | { |
24 | /* Was static char[BIGNUM] */ | 23 | /* Was static char[BIGNUM] */ |
25 | enum { sizeof_passwd = 128 }; | 24 | enum { sizeof_passwd = 128 }; |
26 | static char *passwd; | ||
27 | 25 | ||
26 | char *passwd; | ||
28 | char *ret; | 27 | char *ret; |
29 | int i; | 28 | int i; |
30 | struct sigaction sa, oldsa; | 29 | struct sigaction sa, oldsa; |
@@ -62,8 +61,7 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt) | |||
62 | alarm(timeout); | 61 | alarm(timeout); |
63 | } | 62 | } |
64 | 63 | ||
65 | if (!passwd) | 64 | passwd = auto_string(xmalloc(sizeof_passwd)); |
66 | passwd = xmalloc(sizeof_passwd); | ||
67 | ret = passwd; | 65 | ret = passwd; |
68 | i = 0; | 66 | i = 0; |
69 | while (1) { | 67 | while (1) { |
diff --git a/libbb/human_readable.c b/libbb/human_readable.c index 0b2eb777e..5c7fc076f 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c | |||
@@ -37,8 +37,6 @@ const char* FAST_FUNC make_human_readable_str(unsigned long long val, | |||
37 | '\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' | 37 | '\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' |
38 | }; | 38 | }; |
39 | 39 | ||
40 | static char *str; | ||
41 | |||
42 | unsigned frac; /* 0..9 - the fractional digit */ | 40 | unsigned frac; /* 0..9 - the fractional digit */ |
43 | const char *u; | 41 | const char *u; |
44 | const char *fmt; | 42 | const char *fmt; |
@@ -81,12 +79,7 @@ const char* FAST_FUNC make_human_readable_str(unsigned long long val, | |||
81 | #endif | 79 | #endif |
82 | } | 80 | } |
83 | 81 | ||
84 | if (!str) { | 82 | return auto_string(xasprintf(fmt, val, frac, *u)); |
85 | /* sufficient for any width of val */ | ||
86 | str = xmalloc(sizeof(val)*3 + 2 + 3); | ||
87 | } | ||
88 | sprintf(str, fmt, val, frac, *u); | ||
89 | return str; | ||
90 | } | 83 | } |
91 | 84 | ||
92 | 85 | ||
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 5a6aec6bd..9256567cc 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c | |||
@@ -1142,19 +1142,19 @@ static void signal_handler(int sig) | |||
1142 | 1142 | ||
1143 | static const char *get_variable(const char *variable, void *info) | 1143 | static const char *get_variable(const char *variable, void *info) |
1144 | { | 1144 | { |
1145 | static char sbuf[sizeof(int)*3 + 2]; /* sign and NUL */ | ||
1146 | static char *hostname; | 1145 | static char *hostname; |
1147 | 1146 | ||
1148 | struct get_variable_info *gv_info = info; | 1147 | struct get_variable_info *gv_info = info; |
1149 | const char *field_names[] = { | 1148 | const char *field_names[] = { |
1150 | "hostname", "mntpt", "devpath", "devname", | 1149 | "hostname", "mntpt", "devpath", "devname", "uid", "gid", "mode", |
1151 | "uid", "gid", "mode", hostname, mount_point, | 1150 | NULL, mount_point, gv_info->devpath, gv_info->devname, NULL |
1152 | gv_info->devpath, gv_info->devname, NULL | ||
1153 | }; | 1151 | }; |
1154 | int i; | 1152 | int i; |
1155 | 1153 | ||
1156 | if (!hostname) | 1154 | if (!hostname) |
1157 | hostname = safe_gethostname(); | 1155 | hostname = safe_gethostname(); |
1156 | field_names[7] = hostname; | ||
1157 | |||
1158 | /* index_in_str_array returns i>=0 */ | 1158 | /* index_in_str_array returns i>=0 */ |
1159 | i = index_in_str_array(field_names, variable); | 1159 | i = index_in_str_array(field_names, variable); |
1160 | 1160 | ||
@@ -1164,12 +1164,11 @@ static const char *get_variable(const char *variable, void *info) | |||
1164 | return field_names[i + 7]; | 1164 | return field_names[i + 7]; |
1165 | 1165 | ||
1166 | if (i == 4) | 1166 | if (i == 4) |
1167 | sprintf(sbuf, "%u", gv_info->info->uid); | 1167 | return auto_string(xasprintf("%u", gv_info->info->uid)); |
1168 | else if (i == 5) | 1168 | if (i == 5) |
1169 | sprintf(sbuf, "%u", gv_info->info->gid); | 1169 | return auto_string(xasprintf("%u", gv_info->info->gid)); |
1170 | else if (i == 6) | 1170 | /* i == 6 */ |
1171 | sprintf(sbuf, "%o", gv_info->info->mode); | 1171 | return auto_string(xasprintf("%o", gv_info->info->mode)); |
1172 | return sbuf; | ||
1173 | } /* End Function get_variable */ | 1172 | } /* End Function get_variable */ |
1174 | 1173 | ||
1175 | static void service(struct stat statbuf, char *path) | 1174 | static void service(struct stat statbuf, char *path) |
diff --git a/networking/interface.c b/networking/interface.c index b0572d04e..24bd13c57 100644 --- a/networking/interface.c +++ b/networking/interface.c | |||
@@ -89,13 +89,9 @@ struct in6_ifreq { | |||
89 | /* Display an Internet socket address. */ | 89 | /* Display an Internet socket address. */ |
90 | static const char* FAST_FUNC INET_sprint(struct sockaddr *sap, int numeric) | 90 | static const char* FAST_FUNC INET_sprint(struct sockaddr *sap, int numeric) |
91 | { | 91 | { |
92 | static char *buff; /* defaults to NULL */ | ||
93 | |||
94 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) | 92 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
95 | return "[NONE SET]"; | 93 | return "[NONE SET]"; |
96 | free(buff); | 94 | return auto_string(INET_rresolve((struct sockaddr_in *) sap, numeric, 0xffffff00)); |
97 | buff = INET_rresolve((struct sockaddr_in *) sap, numeric, 0xffffff00); | ||
98 | return buff; | ||
99 | } | 95 | } |
100 | 96 | ||
101 | #ifdef UNUSED_AND_BUGGY | 97 | #ifdef UNUSED_AND_BUGGY |
@@ -171,13 +167,9 @@ static const struct aftype inet_aftype = { | |||
171 | /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ | 167 | /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ |
172 | static const char* FAST_FUNC INET6_sprint(struct sockaddr *sap, int numeric) | 168 | static const char* FAST_FUNC INET6_sprint(struct sockaddr *sap, int numeric) |
173 | { | 169 | { |
174 | static char *buff; | ||
175 | |||
176 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) | 170 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
177 | return "[NONE SET]"; | 171 | return "[NONE SET]"; |
178 | free(buff); | 172 | return auto_string(INET6_rresolve((struct sockaddr_in6 *) sap, numeric)); |
179 | buff = INET6_rresolve((struct sockaddr_in6 *) sap, numeric); | ||
180 | return buff; | ||
181 | } | 173 | } |
182 | 174 | ||
183 | #ifdef UNUSED | 175 | #ifdef UNUSED |
@@ -223,13 +215,11 @@ static const struct aftype inet6_aftype = { | |||
223 | /* Display an UNSPEC address. */ | 215 | /* Display an UNSPEC address. */ |
224 | static char* FAST_FUNC UNSPEC_print(unsigned char *ptr) | 216 | static char* FAST_FUNC UNSPEC_print(unsigned char *ptr) |
225 | { | 217 | { |
226 | static char *buff; | 218 | char *buff; |
227 | |||
228 | char *pos; | 219 | char *pos; |
229 | unsigned int i; | 220 | unsigned int i; |
230 | 221 | ||
231 | if (!buff) | 222 | buff = auto_string(xmalloc(sizeof(struct sockaddr) * 3 + 1)); |
232 | buff = xmalloc(sizeof(struct sockaddr) * 3 + 1); | ||
233 | pos = buff; | 223 | pos = buff; |
234 | for (i = 0; i < sizeof(struct sockaddr); i++) { | 224 | for (i = 0; i < sizeof(struct sockaddr); i++) { |
235 | /* careful -- not every libc's sprintf returns # bytes written */ | 225 | /* careful -- not every libc's sprintf returns # bytes written */ |
@@ -712,14 +702,12 @@ static const struct hwtype loop_hwtype = { | |||
712 | /* Display an Ethernet address in readable format. */ | 702 | /* Display an Ethernet address in readable format. */ |
713 | static char* FAST_FUNC ether_print(unsigned char *ptr) | 703 | static char* FAST_FUNC ether_print(unsigned char *ptr) |
714 | { | 704 | { |
715 | static char *buff; | 705 | char *buff; |
716 | |||
717 | free(buff); | ||
718 | buff = xasprintf("%02X:%02X:%02X:%02X:%02X:%02X", | 706 | buff = xasprintf("%02X:%02X:%02X:%02X:%02X:%02X", |
719 | (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), | 707 | (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), |
720 | (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) | 708 | (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) |
721 | ); | 709 | ); |
722 | return buff; | 710 | return auto_string(buff); |
723 | } | 711 | } |
724 | 712 | ||
725 | static const struct hwtype ether_hwtype = { | 713 | static const struct hwtype ether_hwtype = { |