[git commit] ash: use mempcpy() in more places

Denys Vlasenko vda.linux at googlemail.com
Sun Jul 23 19:46:34 UTC 2017


commit: https://git.busybox.net/busybox/commit/?id=5ace96a71304c2d5d3b8b864df9b4b8ca40f417c
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Most changes are taken from dash.

function                                             old     new   delta
single_quote                                         127     129      +2
stack_nputstr                                         28      29      +1
path_advance                                         209     202      -7
rmescapes                                            346     308     -38
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 3/-45)             Total: -42 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index c8b2adf..fa03f8a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1658,7 +1658,7 @@ static char *
 stack_nputstr(const char *s, size_t n, char *p)
 {
 	p = makestrspace(n, p);
-	p = (char *)memcpy(p, s, n) + n;
+	p = (char *)mempcpy(p, s, n);
 	return p;
 }
 
@@ -1761,7 +1761,7 @@ single_quote(const char *s)
 		q = p = makestrspace(len + 3, p);
 
 		*q++ = '\'';
-		q = (char *)memcpy(q, s, len) + len;
+		q = (char *)mempcpy(q, s, len) + len;
 		*q++ = '\'';
 		s += len;
 
@@ -1775,7 +1775,7 @@ single_quote(const char *s)
 		q = p = makestrspace(len + 3, p);
 
 		*q++ = '"';
-		q = (char *)memcpy(q, s - len, len) + len;
+		q = (char *)mempcpy(q, s - len, len);
 		*q++ = '"';
 
 		STADJUST(q - p, p);
@@ -2453,8 +2453,7 @@ path_advance(const char **path, const char *name)
 		growstackblock();
 	q = stackblock();
 	if (p != start) {
-		memcpy(q, start, p - start);
-		q += p - start;
+		q = mempcpy(q, start, p - start);
 		*q++ = '/';
 	}
 	strcpy(q, name);
@@ -5949,7 +5948,7 @@ rmescapes(char *str, int flag)
 		}
 		q = r;
 		if (len > 0) {
-			q = (char *)memcpy(q, str, len) + len;
+			q = (char *)mempcpy(q, str, len);
 		}
 	}
 


More information about the busybox-cvs mailing list