zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH v2] string.c: remove use of strcat() after strlen()
@ 2023-12-26  6:01 James Tirta Halim
  2023-12-31  4:22 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: James Tirta Halim @ 2023-12-26  6:01 UTC (permalink / raw)
  To: zsh-workers; +Cc: James Tirta Halim

Changes in v2:
return the realloc'd string

---
 Src/string.c | 8 ++++++-
 1 file changed, 7 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);
+    base = realloc(base, base_len + append_len + 1);
+    *(char *)MEMPCPY(base + base_len, append, append_len) = '\0';
+    return base;
 }
 
 /* Return a pointer to the last character of a string,
-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-28  0:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26  6:01 [PATCH v2] string.c: remove use of strcat() after strlen() James Tirta Halim
2023-12-31  4:22 ` Bart Schaefer
2023-12-31  5:10   ` James
2023-12-31  5:20     ` Bart Schaefer
2024-01-28  0:57     ` Oliver Kiddle

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).