Skip to content

Commit

Permalink
safe copy
Browse files Browse the repository at this point in the history
  • Loading branch information
ucwong committed Jun 10, 2023
1 parent 364e638 commit 71e5c8d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@

package common

//func SafeCopy(des, src []byte) []byte {
// return append(des[:0], src...)
//}

func SafeCopy(des, src []byte) []byte {
return append(des[:0], src...)
if len(des) < len(src) {
des = make([]byte, len(src))
} else {
des = des[:len(src)]
}
copy(des, src)
return des
}

0 comments on commit 71e5c8d

Please sign in to comment.