Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ dstr dstrreserve(dstr s, size_t new_cap)
size_t old_hd_size = _dstr_size_by_type(old_type);
size_t new_hd_size = _dstr_size_by_type(new_type);

if (new_cap > SIZE_MAX - new_hd_size)
return NULL;

void* old_hd = (char*)s - old_hd_size;

if (old_type == new_type) {
Expand Down Expand Up @@ -698,6 +701,9 @@ static dstr _dstrnew_allocator(enum dstrhd_type t,
size_t s_len,
size_t alloc_size)
{
if (alloc_size > SIZE_MAX - _dstr_size_by_type(t))
return NULL;

switch (t) {
case DSTRHD_TYPE_8: {
struct dstrhd8* hd = DSTR_MALLOC(sizeof(*hd) + alloc_size);
Expand Down
Loading