Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] string.c: remove use of strcat() after strlen()
- X-seq: zsh-workers 52431
- From: James Tirta Halim <tirtajames45@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Cc: James Tirta Halim <tirtajames45@xxxxxxxxx>
- Subject: [PATCH] string.c: remove use of strcat() after strlen()
- Date: Tue, 26 Dec 2023 12:43:00 +0700
- Archived-at: <https://zsh.org/workers/52431>
- List-id: <zsh-workers.zsh.org>
---
Src/string.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/Src/string.c b/Src/string.c
index 5f439926e..99e31d6c3 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -28,6 +28,8 @@
#include "zsh.mdh"
+#define MEMPCPY(dst, src, n) ((char *)memcpy(dst, src, n) + n)
+
/**/
mod_export char *
dupstring(const char *s)
@@ -200,7 +202,10 @@ ztrduppfx(const char *s, int len)
mod_export char *
appstr(char *base, char const *append)
{
- return strcat(realloc(base, strlen(base) + strlen(append) + 1), append);
+ const size_t base_len = strlen(base);
+ const size_t append_len = strlen(append);
+ *(append = (char *)MEMPCPY((char *)realloc(base, base_len + append_len + 1) + base_len, append, append_len)) = '\0';
+ return append;
}
/* Return a pointer to the last character of a string,
--
2.43.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author