diff src/str.c @ 12:0cc2555db371

*: make our string functions not stupid strncat() made everything slow! new addition internally: an EDL_header structure to make things not stupid. if we were using C++ it wouldn't really be necessary, but alas :)
author Paper <paper@paper.us.eu.org>
date Wed, 27 Mar 2024 13:38:30 -0400
parents 0c98b46eaf73
children 2d7c810a1ac2
line wrap: on
line diff
--- a/src/str.c	Fri Mar 22 20:51:46 2024 -0400
+++ b/src/str.c	Wed Mar 27 13:38:30 2024 -0400
@@ -25,8 +25,8 @@
 	if (!str->data)
 		return 0;
 
-	//if (new_capacity > str->capacity)
-	//	memset(&str->data[str->capacity], 0, (new_capacity - str->capacity) * sizeof(char));
+	if (new_capacity > str->capacity)
+		memset(&str->data[str->capacity], 0, (new_capacity - str->capacity) * sizeof(char));
 
 	str->capacity = new_capacity;
 
@@ -38,6 +38,7 @@
         if (!EDL_internal_string_allocate(str, 1))
             return 0;
 
+    /* increase capacity if needed */
     if (str->size + length + 1 >= str->capacity) {
         size_t capacity = 1;
         while (capacity < (str->size + length + 1))
@@ -47,7 +48,7 @@
             return 0;
     }
 
-    strncat(str->data, data, length);
+    memcpy(&str->data[str->size], data, length);
     str->size += length;
 
     return length;