shithub: masto9

Download patch

ref: cf0458c99c5d0d17e918f62c74b1343568eb3227
parent: 454703e94b801ebe25b61f964d52ad4fbb7bd3d9
author: Julien Blanchard <julien@typed-hole.org>
date: Fri Apr 7 07:17:26 EDT 2023

Update concat

--- a/util.c
+++ b/util.c
@@ -44,11 +44,14 @@
 char *
 concat(char *s1, char *s2)
 {
+	int len1 = strlen(s1);
+	int len2 = strlen(s2);
 	char *result;
-	result = emalloc(strlen(s1) + strlen(s2) + 1); // +1 for the null-terminator
 
-	strcpy(result, s1);
-	strcat(result, s2);
+	result =
+		emalloc(sizeof(char) * (len1 + len2 + 1)); // +1 for the null-terminator
+	memcpy(result, s1, len1);
+	memcpy(result + len1, s2, len2 + 1);
 	return result;
 }