* [PATCH] string.c: remove use of strcat() after strlen()
@ 2023-12-26 5:43 James Tirta Halim
0 siblings, 0 replies; only message in thread
From: James Tirta Halim @ 2023-12-26 5:43 UTC (permalink / raw)
To: zsh-workers; +Cc: James Tirta Halim
---
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-12-26 5:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 5:43 [PATCH] string.c: remove use of strcat() after strlen() James Tirta Halim
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).