diff options
Diffstat (limited to 'libgo/runtime/go-strslice.c')
-rw-r--r-- | libgo/runtime/go-strslice.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libgo/runtime/go-strslice.c b/libgo/runtime/go-strslice.c index c9f196b..0e897812 100644 --- a/libgo/runtime/go-strslice.c +++ b/libgo/runtime/go-strslice.c @@ -17,7 +17,11 @@ __go_string_slice (String s, intgo start, intgo end) end = len; if (start > len || end < start || end > len) runtime_panicstring ("string index out of bounds"); - ret.str = s.str + start; 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) + ret.str = s.str + start; return ret; } |