aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/go-string-to-byte-array.c
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2014-06-06 22:37:27 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2014-06-06 22:37:27 +0000
commit6736ef96eab222e58e6294f42be981a5afb59811 (patch)
tree2bc668fae9bf96f9a3988e0b0a16685bde8c4f0b /libgo/runtime/go-string-to-byte-array.c
parent38a138411da4206c53f9a153ee9c3624fce58a52 (diff)
downloadgcc-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-byte-array.c')
-rw-r--r--libgo/runtime/go-string-to-byte-array.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libgo/runtime/go-string-to-byte-array.c b/libgo/runtime/go-string-to-byte-array.c
index 5e03033..a4edb50 100644
--- a/libgo/runtime/go-string-to-byte-array.c
+++ b/libgo/runtime/go-string-to-byte-array.c
@@ -12,14 +12,17 @@
struct __go_open_array
__go_string_to_byte_array (String str)
{
+ uintptr cap;
unsigned char *data;
struct __go_open_array ret;
- data = (unsigned char *) runtime_mallocgc (str.len, 0,
- FlagNoScan | FlagNoZero);
+ cap = runtime_roundupsize (str.len);
+ data = (unsigned char *) runtime_mallocgc (cap, 0, FlagNoScan | FlagNoZero);
__builtin_memcpy (data, str.str, str.len);
+ if (cap != (uintptr) str.len)
+ __builtin_memset (data + str.len, 0, cap - (uintptr) str.len);
ret.__values = (void *) data;
ret.__count = str.len;
- ret.__capacity = str.len;
+ ret.__capacity = (intgo) cap;
return ret;
}