summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko2020-02-17 15:59:08 +0100
committerDenys Vlasenko2020-02-17 15:59:08 +0100
commitc55847fedbc3cbc10f2558c5449d8635f318ce49 (patch)
tree0e6e83dae9075d330205551cabbc64dae8bac67f /shell
parent74aaf05170d6f224194c98ee0434e2decae45735 (diff)
downloadbusybox-c55847fedbc3cbc10f2558c5449d8635f318ce49.zip
busybox-c55847fedbc3cbc10f2558c5449d8635f318ce49.tar.gz
ash: memalloc: Add growstackto helper
Upstream commit: Date: Sat, 19 May 2018 02:39:46 +0800 memalloc: Add growstackto helper This patch adds the growstackto helper which repeatedly calls growstackblock until the requested size is reached. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/shell/ash.c b/shell/ash.c
index e0ddf71..6505f49 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1740,6 +1740,15 @@ growstackstr(void)
return (char *)stackblock() + len;
}
+static char *
+growstackto(size_t len)
+{
+ while (stackblocksize() < len)
+ growstackblock();
+
+ return stackblock();
+}
+
/*
* Called from CHECKSTRSPACE.
*/
@@ -1747,18 +1756,8 @@ static char *
makestrspace(size_t newlen, char *p)
{
size_t len = p - g_stacknxt;
- size_t size;
-
- for (;;) {
- size_t nleft;
- size = stackblocksize();
- nleft = size - len;
- if (nleft >= newlen)
- break;
- growstackblock();
- }
- return (char *)stackblock() + len;
+ return growstackto(len + newlen) + len;
}
static char *
@@ -2584,9 +2583,7 @@ path_advance(const char **path, const char *name)
for (p = start; *p && *p != ':' && *p != '%'; p++)
continue;
len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */
- while (stackblocksize() < len)
- growstackblock();
- q = stackblock();
+ q = growstackto(len);
if (p != start) {
q = mempcpy(q, start, p - start);
*q++ = '/';
@@ -12836,9 +12833,7 @@ parsebackq: {
/* Ignore any pushed back tokens left from the backquote parsing. */
if (oldstyle)
tokpushback = 0;
- while (stackblocksize() <= savelen)
- growstackblock();
- STARTSTACKSTR(out);
+ out = growstackto(savelen + 1);
if (str) {
memcpy(out, str, savelen);
STADJUST(savelen, out);