From f37ec0554843525285fee6dac54136376aad02ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20P=C3=B6tzschke?= <16013351+dpoetzschke@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:30:56 +0100 Subject: [PATCH] adjust memory allocation --- src/string.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/string.cpp b/src/string.cpp index 6d533e6d9..412889e0f 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -415,7 +415,12 @@ gb_internal String concatenate4_strings(gbAllocator a, String const &x, String c #if defined(GB_SYSTEM_WINDOWS) gb_internal String escape_char(gbAllocator a, String s, char cte) { isize buf_len = s.len; - u8 *buf = gb_alloc_array(a, u8, buf_len); + isize cte_count = 0; + for (isize j = 0; j < s.len; j++) + if (s.text[j] == cte) + cte_count++; + + u8 *buf = gb_alloc_array(a, u8, buf_len+cte_count); isize i = 0; for (isize j = 0; j < s.len; j++) { u8 c = s.text[j];