From: ahmedsamyh Date: Wed, 26 Mar 2025 21:54:12 +0000 (+0500) Subject: [commonlib.h] Fix sv_to_cstr(). X-Git-Url: https://www.git.momoyon.org/?a=commitdiff_plain;h=c6f3818a5c852b26eca56a86d9a4d7f783fcff78;p=commonlib.git [commonlib.h] Fix sv_to_cstr(). --- diff --git a/commonlib.h b/commonlib.h index 2cb0b89..9aa11b3 100644 --- a/commonlib.h +++ b/commonlib.h @@ -607,8 +607,12 @@ void c_sv_trim(c_String_view* sv){ } char* c_sv_to_cstr(c_String_view sv){ - char* res = (char*)calloc(1, sizeof(char)*sv.count); + char* res = (char*)malloc(sizeof(char)*(sv.count + 1)); + if (res == NULL) { + C_ASSERT(false, "Buy more RAM bruh"); + } C_MEMCPY(res, sv.data, sv.count); + res[sv.count] = '\0'; return res; }