From 252093f1203da13e1face4f71141ac75482ccf11 Mon Sep 17 00:00:00 2001 From: Martin Möhrmann Date: Tue, 6 Sep 2016 10:38:16 +0200 Subject: runtime: remove maxstring Before this CL the runtime prevented printing of overlong strings with the print function when the length of the string was determined to be corrupted. Corruption was checked by comparing the string size against the limit which was stored in maxstring. However maxstring was not updated everywhere were go strings were created e.g. for string constants during compile time. Thereby the check for maximum string length prevented the printing of some valid strings. The protection maxstring provided did not warrant the bookkeeping and global synchronization needed to keep maxstring updated to the correct limit everywhere. Fixes #16999 Change-Id: I62cc2f4362f333f75b77f199ce1a71aac0ff7aeb Reviewed-on: https://go-review.googlesource.com/28813 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/runtime/string.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'src/runtime/string.go') diff --git a/src/runtime/string.go b/src/runtime/string.go index 5512f33ea8..2263e16410 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -4,10 +4,7 @@ package runtime -import ( - "runtime/internal/atomic" - "unsafe" -) +import "unsafe" // The constant is known to the compiler. // There is no fundamental theory behind this number. @@ -253,12 +250,7 @@ func rawstring(size int) (s string, b []byte) { *(*slice)(unsafe.Pointer(&b)) = slice{p, size, size} - for { - ms := maxstring - if uintptr(size) <= ms || atomic.Casuintptr((*uintptr)(unsafe.Pointer(&maxstring)), ms, uintptr(size)) { - return - } - } + return } // rawbyteslice allocates a new byte slice. The byte slice is not zeroed. @@ -371,18 +363,10 @@ func findnullw(s *uint16) int { return l } -var maxstring uintptr = 256 // a hint for print - //go:nosplit func gostringnocopy(str *byte) string { ss := stringStruct{str: unsafe.Pointer(str), len: findnull(str)} s := *(*string)(unsafe.Pointer(&ss)) - for { - ms := maxstring - if uintptr(len(s)) <= ms || atomic.Casuintptr(&maxstring, ms, uintptr(len(s))) { - break - } - } return s } -- cgit v1.3-5-g9baa