sv: fix possible runtime issue with NULL SV's in sv_copy

This commit is contained in:
2026-02-05 06:17:52 +00:00
parent df1076f7d7
commit 3add9beb59

View File

@@ -12,6 +12,10 @@
sv_t sv_copy(sv_t old)
{
if (old.size == 0)
return SV(old.data, 0);
else if (old.data == NULL)
return SV(NULL, old.size);
char *newstr = calloc(1, (old.size + 1) * sizeof(*newstr));
memcpy(newstr, old.data, old.size);
newstr[old.size] = '\0';