fix bug in stringInsertBytesAtMaybeAlloc()

This commit is contained in:
Tenari
2026-07-29 07:25:56 -05:00
parent 1c8a0c27b2
commit 2662516d94
2 changed files with 12 additions and 1 deletions
+7
View File
@@ -149,6 +149,13 @@ fn u64 u64SafeMul(u64 x, u64 y) {
fn f32 f32FromString(String s) {
f32 result = 0.0f;
if (s.length == 0) { return result; }
// TODO handle +/- for sign
/*
* while (*s == ' ') s++;
float sign = 1.0f;
if (*s == '-') { sign = -1.0f; s++; }
else if (*s == '+') s++;
* */
ptr c = s.bytes;
while (*c >= '0' && *c <= '9') {
result = result * 10.0f + (*c++ - '0');
+5 -1
View File
@@ -494,7 +494,11 @@ fn bool stringInsertBytesAtMaybeAlloc(Arena* a, String* s, str bytes, u32 at) {
bool is_already_enough_space = stringInsertBytesAt(s, bytes, at);
if (!is_already_enough_space) {
ptr old_bytes = s->bytes;
s->bytes = arenaAllocZero(a, s->capacity + 64);
u32 len = strlen(bytes);
u32 available_cap = s->capacity - s->length;
assert(len > available_cap);
s->capacity += (len - available_cap);
s->bytes = arenaAllocZero(a, s->capacity);
MemoryCopy(s->bytes, old_bytes, s->length);
return stringInsertBytesAt(s, bytes, at);
}