diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-06 22:37:27 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-06 22:37:27 +0000 |
commit | 6736ef96eab222e58e6294f42be981a5afb59811 (patch) | |
tree | 2bc668fae9bf96f9a3988e0b0a16685bde8c4f0b /libgo/runtime/go-string-to-int-array.c | |
parent | 38a138411da4206c53f9a153ee9c3624fce58a52 (diff) | |
download | gcc-6736ef96eab222e58e6294f42be981a5afb59811.zip gcc-6736ef96eab222e58e6294f42be981a5afb59811.tar.gz gcc-6736ef96eab222e58e6294f42be981a5afb59811.tar.bz2 |
libgo: Merge to master revision 19184.
The next revision, 19185, renames several runtime files, and
will be handled in a separate change.
From-SVN: r211328
Diffstat (limited to 'libgo/runtime/go-string-to-int-array.c')
-rw-r--r-- | libgo/runtime/go-string-to-int-array.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libgo/runtime/go-string-to-int-array.c b/libgo/runtime/go-string-to-int-array.c index d91c9e2..5546889 100644 --- a/libgo/runtime/go-string-to-int-array.c +++ b/libgo/runtime/go-string-to-int-array.c @@ -17,6 +17,7 @@ __go_string_to_int_array (String str) size_t c; const unsigned char *p; const unsigned char *pend; + uintptr mem; uint32_t *data; uint32_t *pd; struct __go_open_array ret; @@ -32,8 +33,11 @@ __go_string_to_int_array (String str) p += __go_get_rune (p, pend - p, &rune); } - data = (uint32_t *) runtime_mallocgc (c * sizeof (uint32_t), 0, - FlagNoScan | FlagNoZero); + if (c > MaxMem / sizeof (uint32_t)) + runtime_throw ("out of memory"); + + mem = runtime_roundupsize (c * sizeof (uint32_t)); + data = (uint32_t *) runtime_mallocgc (mem, 0, FlagNoScan | FlagNoZero); p = str.str; pd = data; while (p < pend) @@ -43,9 +47,10 @@ __go_string_to_int_array (String str) p += __go_get_rune (p, pend - p, &rune); *pd++ = rune; } - + if (mem > (uintptr) c * sizeof (uint32_t)) + __builtin_memset (data + c, 0, mem - (uintptr) c * sizeof (uint32_t)); ret.__values = (void *) data; ret.__count = c; - ret.__capacity = c; + ret.__capacity = (intgo) (mem / sizeof (uint32_t)); return ret; } |