2017-06-15 79 views

回答

0

It's checking for overflow

// bytes.Repeat(make([]byte, 255), int((^uint(0))/255+1)) panics with the test. 
// Without the test, it returns a bad result. 

b := make([]byte, 255) 
count := int((^uint(0))/255 + 1) 

fmt.Println("count:", count) // prints 16843010 on the playground 
fmt.Println("len(b):", len(b)) // prints 255 
fmt.Println("count * len(b): ", count*len(b)) // prints 254 
fmt.Println("len(b) * count/count != len(b):", len(b)*count/count != len(b)) // prints false 

https://play.golang.org/p/3OQ0vB0WC4

+0

謝謝你的澄清!我相信你的意思是說'fmt.Println(「len(b)* count/count!= len(b):」,len(b)* count/count!= len(b))'? – shotes