Commit 84c67c3b by Ian Lance Taylor

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

From-SVN: r203140
parent 11b54a5a
...@@ -24,24 +24,24 @@ __go_append (struct __go_open_array a, void *bvalues, uintptr_t bcount, ...@@ -24,24 +24,24 @@ __go_append (struct __go_open_array a, void *bvalues, uintptr_t bcount,
uintptr_t element_size) uintptr_t element_size)
{ {
uintptr_t ucount; uintptr_t ucount;
int count; intgo count;
if (bvalues == NULL || bcount == 0) if (bvalues == NULL || bcount == 0)
return a; return a;
ucount = (uintptr_t) a.__count + bcount; ucount = (uintptr_t) a.__count + bcount;
count = (int) ucount; count = (intgo) ucount;
if ((uintptr_t) count != ucount || count <= a.__count) if ((uintptr_t) count != ucount || count <= a.__count)
runtime_panicstring ("append: slice overflow"); runtime_panicstring ("append: slice overflow");
if (count > a.__capacity) if (count > a.__capacity)
{ {
int m; intgo m;
void *n; void *n;
m = a.__capacity; m = a.__capacity;
if (m == 0) if (m + m < count)
m = (int) bcount; m = count;
else else
{ {
do do
...@@ -54,7 +54,7 @@ __go_append (struct __go_open_array a, void *bvalues, uintptr_t bcount, ...@@ -54,7 +54,7 @@ __go_append (struct __go_open_array a, void *bvalues, uintptr_t bcount,
while (m < count); 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"); runtime_panicstring ("growslice: cap out of range");
n = __go_alloc (m * element_size); n = __go_alloc (m * element_size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment