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:
3
main.c
3
main.c
@@ -20,8 +20,9 @@
|
|||||||
|
|
||||||
sv_t sv_copy(sv_t old)
|
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);
|
memcpy(newstr, old.data, old.size);
|
||||||
|
newstr[old.size] = '\0';
|
||||||
return SV(newstr, old.size);
|
return SV(newstr, old.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user