aboutsummaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorDominik Pötzschke <16013351+dpoetzschke@users.noreply.github.com>2024-10-30 22:30:56 +0100
committerDominik Pötzschke <16013351+dpoetzschke@users.noreply.github.com>2024-10-30 22:30:56 +0100
commitd74f2154900c5d0d1335294265c65e01e44ccf51 (patch)
tree657d008e6ca66b6c8c1034ed092e4df44499bd66 /src/string.cpp
parent6f966f30aab6f739dd65301500a6a0aff67da1d5 (diff)
adjust memory allocation
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/string.cpp b/src/string.cpp
index 14f56e4f0..ff20fb11c 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -414,7 +414,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];