Fix issues with buffer overflow when printing products of sv_copy

Happens because we have no null terminator on the string - rookie
mistake.
This commit is contained in:
2025-08-21 08:34:37 +01:00
parent 7853f637c0
commit e9eaba12d1

3
main.c
View File

@@ -20,8 +20,9 @@
sv_t sv_copy(sv_t old)
{
char *newstr = calloc(1, old.size * sizeof(*newstr));
char *newstr = calloc(1, (old.size + 1) * sizeof(*newstr));
memcpy(newstr, old.data, old.size);
newstr[old.size] = '\0';
return SV(newstr, old.size);
}