diff options
author | Ken Thompson <ken@golang.org> | 2009-05-27 15:56:44 -0700 |
---|---|---|
committer | Ken Thompson <ken@golang.org> | 2009-05-27 15:56:44 -0700 |
commit | e51c033bf4744f29b522e183d3df305803fd1eb0 (patch) | |
tree | 833f008df2831620c5a38c634a7c3fb983f3efc6 | |
parent | 1785290a2976988498fd4d4d2fba358b133ecb53 (diff) | |
download | golang-e51c033bf4744f29b522e183d3df305803fd1eb0.tar.gz |
added protection against race condition
between first and second pass of converting
[]int to string.
R=r
OCL=29467
CL=29467
-rw-r--r-- | src/runtime/string.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/runtime/string.c b/src/runtime/string.c index 04cf06bc3..5bfe8196f 100644 --- a/src/runtime/string.c +++ b/src/runtime/string.c @@ -184,21 +184,25 @@ sys·arraystring(Array b, String s) void sys·arraystringi(Array b, String s) { - int32 siz, i; + int32 siz1, siz2, i; int32 *a; byte dum[8]; a = (int32*)b.array; - siz = 0; + siz1 = 0; for(i=0; i<b.nel; i++) { - siz += runetochar(dum, a[i]); + siz1 += runetochar(dum, a[i]); } - s = gostringsize(siz); - siz = 0; + s = gostringsize(siz1+4); + siz2 = 0; for(i=0; i<b.nel; i++) { - siz += runetochar(s.str+siz, a[i]); + // check for race + if(siz2 >= siz1) + break; + siz2 += runetochar(s.str+siz2, a[i]); } + s.len = siz2; FLUSH(&s); } |