From 00a08d77fc433772cf3f7058328610c41fa074e9 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 12 Jan 2014 10:21:23 +0000 Subject: [PATCH] PackBuffer: slight cleanup in docs --- msg.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/msg.go b/msg.go index e5cc4f68..85b873e2 100644 --- a/msg.go +++ b/msg.go @@ -1293,7 +1293,8 @@ func (dns *Msg) Pack() (msg []byte, err error) { return dns.PackBuffer(nil) } -// PackWithBuffer packs a Msg, reusing a given buffer if possible to reduce memory allocations +// PackBuffer packs a Msg, using the given buffer buf. If buf is too small +// a new buffer is allocated. func (dns *Msg) PackBuffer(buf []byte) (msg []byte, err error) { var dh Header var compression map[string]int @@ -1341,8 +1342,8 @@ func (dns *Msg) PackBuffer(buf []byte) (msg []byte, err error) { dh.Arcount = uint16(len(extra)) msg = buf - if packLen := dns.packLen(); len(msg) <= packLen { - msg = make([]byte, packLen+1) + if packLen := dns.packLen()+1; len(msg) < packLen { + msg = make([]byte, packLen) } // Pack it in: header and then the pieces.