执行:字节。重复检查是否溢出

In Go's bytes package line 412 of bytes.go, there is a condition that goes as follows: (https://golang.org/src/bytes/bytes.go?s=10462:10501#L412)

len(b)*count/count != len(b)

This should apparently check for overflow but I don't understand how. Is this checking for some overflow of the underlying data type for integer? Or is this an error in implementation? len(b)*count/count should always be len(b)...no?

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