Commit 4d034b52 by Ian Lance Taylor

runtime: always initialize str field in __go_string_slice result

    
    Reviewed-on: https://go-review.googlesource.com/64110

From-SVN: r252953
parent e1227692
abe58fdc529378706d65d6b22e4871646eb9023e be69546afcac182cc93c569bc96665f0ef72d66a
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -18,10 +18,13 @@ __go_string_slice (String s, intgo start, intgo end) ...@@ -18,10 +18,13 @@ __go_string_slice (String s, intgo start, intgo end)
if (start > len || end < start || end > len) if (start > len || end < start || end > len)
runtime_panicstring ("string index out of bounds"); runtime_panicstring ("string index out of bounds");
ret.len = end - start; ret.len = end - start;
// If the length of the new string is zero, don't adjust the str // If the length of the new string is zero, the str field doesn't
// field. This ensures that we don't create a pointer to the next // matter, so just set it to nil. This avoids the problem of
// memory block, and thus keep it live unnecessarily. // s.str + start pointing just past the end of the string,
if (ret.len > 0) // which may keep the next memory block alive unnecessarily.
if (ret.len == 0)
ret.str = nil;
else
ret.str = s.str + start; ret.str = s.str + start;
return ret; return ret;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment