go 切片索引很诡异的现象?

shileislslsl · · 850 次点击
我本地ubunto go version go1.11 linux/amd64
#2
更多评论
你是什么环境? 这是我的执行结果 0 panic: runtime error: index out of range
#1
``` stone@stone:/data/ipetservice/src$ cat new_te.go package main import ( "fmt" "math/rand" "time" ) var ( intChan chan int SignChan chan struct{} ) func GetInt() { rand.Seed(time.Now().Unix()) n := rand.Int() % 10 fmt.Println(n) time.Sleep(time.Duration(n) * time.Second) intChan <- n } func pKCS5UnPadding(origData []byte) []byte { length := len(origData) fmt.Println(length) unpadding := int(origData[length-1]) fmt.Println(unpadding) return origData[:(length - unpadding)] } func main() { pKCS5UnPadding([]byte{}) } stone@stone:/data/ipetservice/src$ go run new_te.go 0 0 stone@stone:/data/ipetservice/src$ ```
#3