runtime: Fix append of slice with elements of zero size.

From-SVN: r203140
This commit is contained in:
Ian Lance Taylor 2013-10-02 23:49:39 +00:00
parent 11b54a5a07
commit 84c67c3bae

View File

@ -24,24 +24,24 @@ __go_append (struct __go_open_array a, void *bvalues, uintptr_t bcount,
uintptr_t element_size)
{
uintptr_t ucount;
int count;
intgo count;
if (bvalues == NULL || bcount == 0)
return a;
ucount = (uintptr_t) a.__count + bcount;
count = (int) ucount;
count = (intgo) ucount;
if ((uintptr_t) count != ucount || count <= a.__count)
runtime_panicstring ("append: slice overflow");
if (count > a.__capacity)
{
int m;
intgo m;
void *n;
m = a.__capacity;
if (m == 0)
m = (int) bcount;
if (m + m < count)
m = count;
else
{
do
@ -54,7 +54,7 @@ __go_append (struct __go_open_array a, void *bvalues, uintptr_t bcount,
while (m < count);
}
if ((uintptr) m > MaxMem / element_size)
if (element_size > 0 && (uintptr) m > MaxMem / element_size)
runtime_panicstring ("growslice: cap out of range");
n = __go_alloc (m * element_size);