```
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{})
}
```
执行结果
0
0
Process exiting with code: 0
我对这个结果是完全看不懂,对长度为零的切片取-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
更多评论