Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2409 from ibuclaw/pr2258
Browse files Browse the repository at this point in the history
Fix issue 19128 - argument to alloca may be too large
  • Loading branch information
wilzbach committed Dec 18, 2018
2 parents 286479b + f6ef2b8 commit ab890e0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/rt/arrayassign.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ extern (C) void[] _d_arrayassign(TypeInfo ti, void[] from, void[] to)

// Need a temporary buffer tmp[] big enough to hold one element
void[16] buf = void;
void* ptmp = (elementSize > buf.sizeof) ? alloca(elementSize) : buf.ptr;
void* ptmp = (elementSize > buf.sizeof) ? malloc(elementSize) : buf.ptr;
scope (exit)
{
if (ptmp != buf.ptr)
free(ptmp);
}
return _d_arrayassign_l(ti, from, to, ptmp);
}

Expand Down Expand Up @@ -206,24 +211,20 @@ extern (C) void* _d_arraysetassign(void* p, void* value, int count, TypeInfo ti)

auto element_size = ti.tsize;

//Need a temporary buffer tmp[] big enough to hold one element
void[16] buf = void;
void[] tmp;
if (element_size > buf.sizeof)
{
tmp = alloca(element_size)[0 .. element_size];
}
else
tmp = buf[];
// Need a temporary buffer tmp[] big enough to hold one element
immutable maxAllocaSize = 512;
void *ptmp = (element_size > maxAllocaSize) ? malloc(element_size) : alloca(element_size);

foreach (i; 0 .. count)
{
memcpy(tmp.ptr, p, element_size);
memcpy(ptmp, p, element_size);
memcpy(p, value, element_size);
ti.postblit(p);
ti.destroy(tmp.ptr);
ti.destroy(ptmp);
p += element_size;
}
if (element_size > maxAllocaSize)
free(ptmp);
return pstart;
}

Expand Down

0 comments on commit ab890e0

Please sign in to comment.