summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbb/bb_askpass.c6
-rw-r--r--libbb/human_readable.c9
-rw-r--r--miscutils/devfsd.c19
-rw-r--r--networking/interface.c24
4 files changed, 18 insertions, 40 deletions
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c
index 1927ba9..c2580b9 100644
--- a/libbb/bb_askpass.c
+++ b/libbb/bb_askpass.c
@@ -1,7 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
* Ask for a password
- * I use a static buffer in this function. Plan accordingly.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
*
@@ -23,8 +22,8 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
{
/* Was static char[BIGNUM] */
enum { sizeof_passwd = 128 };
- static char *passwd;
+ char *passwd;
char *ret;
int i;
struct sigaction sa, oldsa;
@@ -62,8 +61,7 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
alarm(timeout);
}
- if (!passwd)
- passwd = xmalloc(sizeof_passwd);
+ passwd = auto_string(xmalloc(sizeof_passwd));
ret = passwd;
i = 0;
while (1) {
diff --git a/libbb/human_readable.c b/libbb/human_readable.c
index 0b2eb77..5c7fc07 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,
'\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
};
- static char *str;
-
unsigned frac; /* 0..9 - the fractional digit */
const char *u;
const char *fmt;
@@ -81,12 +79,7 @@ const char* FAST_FUNC make_human_readable_str(unsigned long long val,
#endif
}
- if (!str) {
- /* sufficient for any width of val */
- str = xmalloc(sizeof(val)*3 + 2 + 3);
- }
- sprintf(str, fmt, val, frac, *u);
- return str;
+ return auto_string(xasprintf(fmt, val, frac, *u));
}
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index 5a6aec6..9256567 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -1142,19 +1142,19 @@ static void signal_handler(int sig)
static const char *get_variable(const char *variable, void *info)
{
- static char sbuf[sizeof(int)*3 + 2]; /* sign and NUL */
static char *hostname;
struct get_variable_info *gv_info = info;
const char *field_names[] = {
- "hostname", "mntpt", "devpath", "devname",
- "uid", "gid", "mode", hostname, mount_point,
- gv_info->devpath, gv_info->devname, NULL
+ "hostname", "mntpt", "devpath", "devname", "uid", "gid", "mode",
+ NULL, mount_point, gv_info->devpath, gv_info->devname, NULL
};
int i;
if (!hostname)
hostname = safe_gethostname();
+ field_names[7] = hostname;
+
/* index_in_str_array returns i>=0 */
i = index_in_str_array(field_names, variable);
@@ -1164,12 +1164,11 @@ static const char *get_variable(const char *variable, void *info)
return field_names[i + 7];
if (i == 4)
- sprintf(sbuf, "%u", gv_info->info->uid);
- else if (i == 5)
- sprintf(sbuf, "%u", gv_info->info->gid);
- else if (i == 6)
- sprintf(sbuf, "%o", gv_info->info->mode);
- return sbuf;
+ return auto_string(xasprintf("%u", gv_info->info->uid));
+ if (i == 5)
+ return auto_string(xasprintf("%u", gv_info->info->gid));
+ /* i == 6 */
+ return auto_string(xasprintf("%o", gv_info->info->mode));
} /* End Function get_variable */
static void service(struct stat statbuf, char *path)
diff --git a/networking/interface.c b/networking/interface.c
index b0572d0..24bd13c 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -89,13 +89,9 @@ struct in6_ifreq {
/* Display an Internet socket address. */
static const char* FAST_FUNC INET_sprint(struct sockaddr *sap, int numeric)
{
- static char *buff; /* defaults to NULL */
-
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return "[NONE SET]";
- free(buff);
- buff = INET_rresolve((struct sockaddr_in *) sap, numeric, 0xffffff00);
- return buff;
+ return auto_string(INET_rresolve((struct sockaddr_in *) sap, numeric, 0xffffff00));
}
#ifdef UNUSED_AND_BUGGY
@@ -171,13 +167,9 @@ static const struct aftype inet_aftype = {
/* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */
static const char* FAST_FUNC INET6_sprint(struct sockaddr *sap, int numeric)
{
- static char *buff;
-
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return "[NONE SET]";
- free(buff);
- buff = INET6_rresolve((struct sockaddr_in6 *) sap, numeric);
- return buff;
+ return auto_string(INET6_rresolve((struct sockaddr_in6 *) sap, numeric));
}
#ifdef UNUSED
@@ -223,13 +215,11 @@ static const struct aftype inet6_aftype = {
/* Display an UNSPEC address. */
static char* FAST_FUNC UNSPEC_print(unsigned char *ptr)
{
- static char *buff;
-
+ char *buff;
char *pos;
unsigned int i;
- if (!buff)
- buff = xmalloc(sizeof(struct sockaddr) * 3 + 1);
+ buff = auto_string(xmalloc(sizeof(struct sockaddr) * 3 + 1));
pos = buff;
for (i = 0; i < sizeof(struct sockaddr); i++) {
/* careful -- not every libc's sprintf returns # bytes written */
@@ -712,14 +702,12 @@ static const struct hwtype loop_hwtype = {
/* Display an Ethernet address in readable format. */
static char* FAST_FUNC ether_print(unsigned char *ptr)
{
- static char *buff;
-
- free(buff);
+ char *buff;
buff = xasprintf("%02X:%02X:%02X:%02X:%02X:%02X",
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
);
- return buff;
+ return auto_string(buff);
}
static const struct hwtype ether_hwtype = {