Skip to content

Commit

Permalink
Merge pull request #94 from ucwong/dev
Browse files Browse the repository at this point in the history
safe copy
  • Loading branch information
ucwong authored Jun 10, 2023
2 parents eacbfdc + 71e5c8d commit 771f6af
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 771f6af

Please sign in to comment.