Check length of copy to be extra sure we are copying whole thing

This commit is contained in:
Jakub Sztandera
2016-11-17 19:24:12 +01:00
parent 9116bf8025
commit ba97b640bd

5
cid.go
View File

@@ -191,7 +191,10 @@ func (c *Cid) bytesV1() []byte {
buf := make([]byte, 2*binary.MaxVarintLen64+len(c.hash))
n := binary.PutUvarint(buf, c.version)
n += binary.PutUvarint(buf[n:], c.codec)
copy(buf[n:], c.hash)
cn := copy(buf[n:], c.hash)
if cn != len(c.hash) {
panic("copy hash length is inconsistent")
}
return buf[:n+len(c.hash)]
}