Bugfix int parsing

This commit is contained in:
Bruce Hill 2024-09-02 19:23:35 -04:00
parent b0a8404bd7
commit a4454df4b9
2 changed files with 10 additions and 4 deletions

View File

@ -442,10 +442,16 @@ static void u8_buf_append(Text_t text, char **buf, size_t *capacity, int64_t *i)
public const char *Text$as_c_string(Text_t text)
{
size_t capacity = text.length;
size_t capacity = text.length + 1;
char *buf = GC_MALLOC_ATOMIC(capacity);
int64_t i = 0;
u8_buf_append(text, &buf, &capacity, &i);
if (i + 1 > (int64_t)capacity) {
capacity = i + 1;
buf = GC_REALLOC(buf, capacity);
}
buf[i] = '\0';
return buf;
}

View File

@ -1,5 +1,5 @@
extern CORD_cat:func(a:Text, b:Text)->Text
extern sqrt:func(n:Num)->Num
func main():
>> CORD_cat("hello ", "world")
= "hello world"
>> sqrt(4)
= 2