diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-02-17 15:59:08 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-02-17 15:59:08 +0100 |
commit | c55847fedbc3cbc10f2558c5449d8635f318ce49 (patch) | |
tree | 0e6e83dae9075d330205551cabbc64dae8bac67f | |
parent | 74aaf05170d6f224194c98ee0434e2decae45735 (diff) | |
download | busybox-w32-c55847fedbc3cbc10f2558c5449d8635f318ce49.tar.gz busybox-w32-c55847fedbc3cbc10f2558c5449d8635f318ce49.tar.bz2 busybox-w32-c55847fedbc3cbc10f2558c5449d8635f318ce49.zip |
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>
-rw-r--r-- | shell/ash.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/shell/ash.c b/shell/ash.c index e0ddf7198..6505f4984 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -1740,6 +1740,15 @@ growstackstr(void) | |||
1740 | return (char *)stackblock() + len; | 1740 | return (char *)stackblock() + len; |
1741 | } | 1741 | } |
1742 | 1742 | ||
1743 | static char * | ||
1744 | growstackto(size_t len) | ||
1745 | { | ||
1746 | while (stackblocksize() < len) | ||
1747 | growstackblock(); | ||
1748 | |||
1749 | return stackblock(); | ||
1750 | } | ||
1751 | |||
1743 | /* | 1752 | /* |
1744 | * Called from CHECKSTRSPACE. | 1753 | * Called from CHECKSTRSPACE. |
1745 | */ | 1754 | */ |
@@ -1747,18 +1756,8 @@ static char * | |||
1747 | makestrspace(size_t newlen, char *p) | 1756 | makestrspace(size_t newlen, char *p) |
1748 | { | 1757 | { |
1749 | size_t len = p - g_stacknxt; | 1758 | size_t len = p - g_stacknxt; |
1750 | size_t size; | ||
1751 | |||
1752 | for (;;) { | ||
1753 | size_t nleft; | ||
1754 | 1759 | ||
1755 | size = stackblocksize(); | 1760 | return growstackto(len + newlen) + len; |
1756 | nleft = size - len; | ||
1757 | if (nleft >= newlen) | ||
1758 | break; | ||
1759 | growstackblock(); | ||
1760 | } | ||
1761 | return (char *)stackblock() + len; | ||
1762 | } | 1761 | } |
1763 | 1762 | ||
1764 | static char * | 1763 | static char * |
@@ -2584,9 +2583,7 @@ path_advance(const char **path, const char *name) | |||
2584 | for (p = start; *p && *p != ':' && *p != '%'; p++) | 2583 | for (p = start; *p && *p != ':' && *p != '%'; p++) |
2585 | continue; | 2584 | continue; |
2586 | len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */ | 2585 | len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */ |
2587 | while (stackblocksize() < len) | 2586 | q = growstackto(len); |
2588 | growstackblock(); | ||
2589 | q = stackblock(); | ||
2590 | if (p != start) { | 2587 | if (p != start) { |
2591 | q = mempcpy(q, start, p - start); | 2588 | q = mempcpy(q, start, p - start); |
2592 | *q++ = '/'; | 2589 | *q++ = '/'; |
@@ -12836,9 +12833,7 @@ parsebackq: { | |||
12836 | /* Ignore any pushed back tokens left from the backquote parsing. */ | 12833 | /* Ignore any pushed back tokens left from the backquote parsing. */ |
12837 | if (oldstyle) | 12834 | if (oldstyle) |
12838 | tokpushback = 0; | 12835 | tokpushback = 0; |
12839 | while (stackblocksize() <= savelen) | 12836 | out = growstackto(savelen + 1); |
12840 | growstackblock(); | ||
12841 | STARTSTACKSTR(out); | ||
12842 | if (str) { | 12837 | if (str) { |
12843 | memcpy(out, str, savelen); | 12838 | memcpy(out, str, savelen); |
12844 | STADJUST(savelen, out); | 12839 | STADJUST(savelen, out); |