minor changes as requested in the review

This commit is contained in:
Nicola Murino 2020-03-10 15:35:56 +01:00
parent 3ea9f24c15
commit 0f0e40a3a6
2 changed files with 4 additions and 3 deletions

View File

@ -586,9 +586,9 @@ func (p *sshFxpReadPacket) UnmarshalBinary(b []byte) error {
func (p *sshFxpReadPacket) getDataSlice() []byte {
dataLen := clamp(p.Len, maxTxPacket)
// we allocate a slice with a bigger capacity so we avoid a new allocation in MarshalBinary and in sendPacket
// we need 9 bytes in MarshalBinary and 4 bytes in sendPacket
return make([]byte, dataLen, dataLen+13)
// we allocate a slice with a bigger capacity so we avoid a new allocation in sshFxpDataPacket.MarshalBinary
// and in sendPacket, we need 9 bytes in MarshalBinary and 4 bytes in sendPacket
return make([]byte, dataLen, dataLen+9+4)
}
type sshFxpRenamePacket struct {

View File

@ -265,6 +265,7 @@ func handlePacket(s *Server, p orderedRequest) error {
ID: p.ID,
Length: uint32(n),
Data: data[:n],
// do not use data[:n:n] here to clamp the capacity, we allocated extra capacity above to avoid reallocations
}
}
if err != nil {