Skip to content

Commit

Permalink
docs:更新安全编码
Browse files Browse the repository at this point in the history
  • Loading branch information
dablelv committed Jul 28, 2024
1 parent 88e9baa commit e5bb7a2
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions 第五篇:安全编码/安全编码.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

# 1.内存管理
# 1.内存管理
## 切片长度校验
操作 slice 时,必须判断长度是否合法,防止程序 panic。
```go
Expand All @@ -17,7 +16,6 @@ func foo(slice []int){
fmt.Println("no enough elems in slice")
}
```

## 指针判空
进行指针操作时,必须判断该指针是否为 nil,防止程序 panic,尤其在 Unmarshal 结构体时。
```go
Expand Down Expand Up @@ -82,7 +80,6 @@ func overflow(n int32) {
- 作为数组索引
- 作为对象的长度或者大小
- 作为数组的边界(如作为循环计数器)

## make 分配长度验证
使用 make 分配内存时,需要对外部输入长度进行校验,防止程序 panic。
```go
Expand Down

0 comments on commit e5bb7a2

Please sign in to comment.