fix bug in stringInsertBytesAtMaybeAlloc()
This commit is contained in:
@@ -149,6 +149,13 @@ fn u64 u64SafeMul(u64 x, u64 y) {
|
|||||||
fn f32 f32FromString(String s) {
|
fn f32 f32FromString(String s) {
|
||||||
f32 result = 0.0f;
|
f32 result = 0.0f;
|
||||||
if (s.length == 0) { return result; }
|
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;
|
ptr c = s.bytes;
|
||||||
while (*c >= '0' && *c <= '9') {
|
while (*c >= '0' && *c <= '9') {
|
||||||
result = result * 10.0f + (*c++ - '0');
|
result = result * 10.0f + (*c++ - '0');
|
||||||
|
|||||||
@@ -494,7 +494,11 @@ fn bool stringInsertBytesAtMaybeAlloc(Arena* a, String* s, str bytes, u32 at) {
|
|||||||
bool is_already_enough_space = stringInsertBytesAt(s, bytes, at);
|
bool is_already_enough_space = stringInsertBytesAt(s, bytes, at);
|
||||||
if (!is_already_enough_space) {
|
if (!is_already_enough_space) {
|
||||||
ptr old_bytes = s->bytes;
|
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);
|
MemoryCopy(s->bytes, old_bytes, s->length);
|
||||||
return stringInsertBytesAt(s, bytes, at);
|
return stringInsertBytesAt(s, bytes, at);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user