diff options
author | siddharth <s@ricketyspace.net> | 2021-06-05 16:29:41 -0400 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2021-06-05 16:29:41 -0400 |
commit | 3e5b67b5f6e8bc703f4497f37611e1058a5d3c78 (patch) | |
tree | 9e3751183facbc6768950b4c6521478b455386bc /lib | |
parent | 9b74672bd7ba63be4eeb13b1a07535e950e08920 (diff) |
lib: update `BytesInCommon`
Ensure that the returned `common` array does not point to any of the
[]byte arrays in `bbytes`.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/byte.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/byte.go b/lib/byte.go index 149be2a..a29a7b0 100644 --- a/lib/byte.go +++ b/lib/byte.go @@ -16,11 +16,13 @@ func ByteInBytes(b byte, bs []byte) bool { // Returns bytes that are common in the given array of array of bytes // `bbytes`. func BytesInCommon(bbytes [][]byte) []byte { - common := make([]byte, 0) + var common []byte switch l := len(bbytes); { case l == 1: - common = bbytes[0] + common = make([]byte, len(bbytes[0])) + copy(common, bbytes[0]) case l > 1: + common = make([]byte, 0) commonRest := BytesInCommon(bbytes[1:]) for _, b := range bbytes[0] { if ByteInBytes(b, commonRest) { |