From 588ffed86c777b6270c341fffadbbfb82f2c6a9c Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 25 Aug 2014 14:38:19 -0400 Subject: cmd/gc, runtime: treat slices and strings like pointers in garbage collection Before, a slice with cap=0 or a string with len=0 might have its base pointer pointing beyond the actual slice/string data into the next block. The collector had to ignore slices and strings with cap=0 in order to avoid misinterpreting the base pointer. Now, a slice with cap=0 or a string with len=0 still has a base pointer pointing into the actual slice/string data, no matter what. The collector can now always scan the pointer, which means strings and slices are no longer special. Fixes issue 8404. LGTM=khr, josharian R=josharian, khr, dvyukov CC=golang-codereviews https://codereview.appspot.com/112570044 --- src/cmd/gc/walk.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/cmd/gc/walk.c') diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c index f3886cf73..c251af660 100644 --- a/src/cmd/gc/walk.c +++ b/src/cmd/gc/walk.c @@ -2875,14 +2875,14 @@ sliceany(Node* n, NodeList **init) lb = N; } - // dynamic checks convert all bounds to unsigned to save us the bound < 0 comparison - // generate - // if hb > bound || lb > hb { panicslice() } + // Checking src[lb:hb:cb] or src[lb:hb]. + // if chk0 || chk1 || chk2 { panicslice() } chk = N; - chk0 = N; - chk1 = N; - chk2 = N; + chk0 = N; // cap(src) < cb + chk1 = N; // cb < hb for src[lb:hb:cb]; cap(src) < hb for src[lb:hb] + chk2 = N; // hb < lb + // All comparisons are unsigned to avoid testing < 0. bt = types[simtype[TUINT]]; if(cb != N && cb->type->width > 4) bt = types[TUINT64]; -- cgit v1.2.1