diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-09-18 22:29:45 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-09-18 22:29:45 +0000 |
commit | 4d034b52593c40db9ceeaa531eefdb628fa29ce5 (patch) | |
tree | 14d9534e0e34d1b35748d66ef2e1d01619fde7f7 | |
parent | e1227692dde1874906f7b07fd60101336efdc0fa (diff) | |
download | gcc-4d034b52593c40db9ceeaa531eefdb628fa29ce5.zip gcc-4d034b52593c40db9ceeaa531eefdb628fa29ce5.tar.gz gcc-4d034b52593c40db9ceeaa531eefdb628fa29ce5.tar.bz2 |
runtime: always initialize str field in __go_string_slice result
Reviewed-on: https://go-review.googlesource.com/64110
From-SVN: r252953
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | libgo/runtime/go-strslice.c | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 4081aa9..27bcb6e 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -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. diff --git a/libgo/runtime/go-strslice.c b/libgo/runtime/go-strslice.c index 0e897812..d51c249 100644 --- a/libgo/runtime/go-strslice.c +++ b/libgo/runtime/go-strslice.c @@ -18,10 +18,13 @@ __go_string_slice (String s, intgo start, intgo end) 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; } |