]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove maxstring
authorMartin Möhrmann <martisch@uos.de>
Tue, 6 Sep 2016 08:38:16 +0000 (10:38 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 8 Sep 2016 15:57:01 +0000 (15:57 +0000)
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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/export_test.go
src/runtime/print.go
src/runtime/string.go
src/runtime/string_test.go

index 199a049431a93b5dd957f656f1411c30e6f65527..a24d7188f3d126faa53e6696aea82c20aeb41910 100644 (file)
@@ -167,9 +167,6 @@ func GostringW(w []uint16) (s string) {
        return
 }
 
-var Gostringnocopy = gostringnocopy
-var Maxstring = &maxstring
-
 type Uintreg sys.Uintreg
 
 var Open = open
index 32626c1e9dff14e3ced2b37906340eb004aadc2e..5f8233524463da706547319c878b84cee926bc4f 100644 (file)
@@ -199,10 +199,6 @@ func printpointer(p unsafe.Pointer) {
 }
 
 func printstring(s string) {
-       if uintptr(len(s)) > maxstring {
-               gwrite(bytes("[string too long]"))
-               return
-       }
        gwrite(bytes(s))
 }
 
index 5512f33ea87dba6be0f962b66dac5afdddcd164b..2263e164100e5eb210ba8096d85e7756dcb215ce 100644 (file)
@@ -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
 }
 
index b1757f0721aa4b3ddb1a547f9ef184432034fb14..6aab0ed7647a1812a63462bc70eb3102bf341061 100644 (file)
@@ -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) {
        s := strings.Repeat("x", sizeNoStack)
        b := []byte(s)