From: Ian Lance Taylor Date: Wed, 2 Oct 2013 23:49:39 +0000 (+0000) Subject: runtime: Fix append of slice with elements of zero size. X-Git-Tag: releases/gcc-4.9.0~3737 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=84c67c3baee4517c0ba8cf0d01c4f3750e2f4b3f;p=thirdparty%2Fgcc.git runtime: Fix append of slice with elements of zero size. From-SVN: r203140 --- diff --git a/libgo/runtime/go-append.c b/libgo/runtime/go-append.c index 12fe876cb95e..8d5dee21616c 100644 --- a/libgo/runtime/go-append.c +++ b/libgo/runtime/go-append.c @@ -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);