This patch to libgo alwayss initializes the str field in the result of
__go_string_slice.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE     (revision 252866)
+++ gcc/go/gofrontend/MERGE     (working copy)
@@ -1,4 +1,4 @@
-abe58fdc529378706d65d6b22e4871646eb9023e
+be69546afcac182cc93c569bc96665f0ef72d66a
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/runtime/go-strslice.c
===================================================================
--- libgo/runtime/go-strslice.c (revision 251948)
+++ libgo/runtime/go-strslice.c (working copy)
@@ -18,10 +18,13 @@ __go_string_slice (String s, intgo start
   if (start > len || end < start || end > len)
     runtime_panicstring ("string index out of bounds");
   ret.len = end - start;
-  // If the length of the new string is zero, don't adjust the str
-  // field.  This ensures that we don't create a pointer to the next
-  // memory block, and thus keep it live unnecessarily.
-  if (ret.len > 0)
+  // If the length of the new string is zero, the str field doesn't
+  // matter, so just set it to nil.  This avoids the problem of
+  // s.str + start pointing just past the end of the string,
+  // which may keep the next memory block alive unnecessarily.
+  if (ret.len == 0)
+    ret.str = nil;
+  else
     ret.str = s.str + start;
   return ret;
 }

Reply via email to