Go:字节。重复检查溢出
在Go的bytes.Go的bytes包第412行中,有一个条件如下:() 这显然应该检查溢出,但我不明白如何。这是在检查integer的基础数据类型是否存在溢出?或者这是实施中的错误Go:字节。重复检查溢出,go,Go,在Go的bytes.Go的bytes包第412行中,有一个条件如下:() 这显然应该检查溢出,但我不明白如何。这是在检查integer的基础数据类型是否存在溢出?或者这是实施中的错误len(b)*count/count应始终为len(b)…否? 感谢您的澄清!我相信你的意思是说fmt.Println(“len(b)*count/count!=len(b):”,len(b)*count/count!=len(b))?谢谢你的澄清!我相信你的意思是说fmt.Println(“len(b)*coun
len(b)*count/count
应始终为len(b)
…否?
感谢您的澄清!我相信你的意思是说
fmt.Println(“len(b)*count/count!=len(b):”,len(b)*count/count!=len(b))
?谢谢你的澄清!我相信你的意思是说fmt.Println(“len(b)*count/count!=len(b):”,len(b)*count/count!=len(b))
?
len(b)*count/count != len(b)
// 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