Commit 252093f1 authored by Martin Möhrmann's avatar Martin Möhrmann Committed by Brad Fitzpatrick

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/28813Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent fd975c6a
...@@ -167,9 +167,6 @@ func GostringW(w []uint16) (s string) { ...@@ -167,9 +167,6 @@ func GostringW(w []uint16) (s string) {
return return
} }
var Gostringnocopy = gostringnocopy
var Maxstring = &maxstring
type Uintreg sys.Uintreg type Uintreg sys.Uintreg
var Open = open var Open = open
......
...@@ -199,10 +199,6 @@ func printpointer(p unsafe.Pointer) { ...@@ -199,10 +199,6 @@ func printpointer(p unsafe.Pointer) {
} }
func printstring(s string) { func printstring(s string) {
if uintptr(len(s)) > maxstring {
gwrite(bytes("[string too long]"))
return
}
gwrite(bytes(s)) gwrite(bytes(s))
} }
......
...@@ -4,10 +4,7 @@ ...@@ -4,10 +4,7 @@
package runtime package runtime
import ( import "unsafe"
"runtime/internal/atomic"
"unsafe"
)
// The constant is known to the compiler. // The constant is known to the compiler.
// There is no fundamental theory behind this number. // There is no fundamental theory behind this number.
...@@ -253,12 +250,7 @@ func rawstring(size int) (s string, b []byte) { ...@@ -253,12 +250,7 @@ func rawstring(size int) (s string, b []byte) {
*(*slice)(unsafe.Pointer(&b)) = slice{p, size, size} *(*slice)(unsafe.Pointer(&b)) = slice{p, size, size}
for { return
ms := maxstring
if uintptr(size) <= ms || atomic.Casuintptr((*uintptr)(unsafe.Pointer(&maxstring)), ms, uintptr(size)) {
return
}
}
} }
// rawbyteslice allocates a new byte slice. The byte slice is not zeroed. // rawbyteslice allocates a new byte slice. The byte slice is not zeroed.
...@@ -371,18 +363,10 @@ func findnullw(s *uint16) int { ...@@ -371,18 +363,10 @@ func findnullw(s *uint16) int {
return l return l
} }
var maxstring uintptr = 256 // a hint for print
//go:nosplit //go:nosplit
func gostringnocopy(str *byte) string { func gostringnocopy(str *byte) string {
ss := stringStruct{str: unsafe.Pointer(str), len: findnull(str)} ss := stringStruct{str: unsafe.Pointer(str), len: findnull(str)}
s := *(*string)(unsafe.Pointer(&ss)) s := *(*string)(unsafe.Pointer(&ss))
for {
ms := maxstring
if uintptr(len(s)) <= ms || atomic.Casuintptr(&maxstring, ms, uintptr(len(s))) {
break
}
}
return s return s
} }
......
...@@ -162,19 +162,6 @@ func TestLargeStringConcat(t *testing.T) { ...@@ -162,19 +162,6 @@ func TestLargeStringConcat(t *testing.T) {
} }
} }
func TestGostringnocopy(t *testing.T) {
max := *runtime.Maxstring
b := make([]byte, max+10)
for i := uintptr(0); i < max+9; i++ {
b[i] = 'a'
}
_ = runtime.Gostringnocopy(&b[0])
newmax := *runtime.Maxstring
if newmax != max+9 {
t.Errorf("want %d, got %d", max+9, newmax)
}
}
func TestCompareTempString(t *testing.T) { func TestCompareTempString(t *testing.T) {
s := strings.Repeat("x", sizeNoStack) s := strings.Repeat("x", sizeNoStack)
b := []byte(s) b := []byte(s)
......
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