diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-07-16 06:54:42 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-07-16 06:54:42 +0000 |
commit | be47d6eceffd2c5dbbc1566d5eea490527fb2bd4 (patch) | |
tree | 0e8fda573576bb4181dba29d0e88380a8c38fafd /libgo/go/syscall/sockcmsg_unix.go | |
parent | efb30cdeb003fd7c585ee0d7657340086abcbd9e (diff) | |
download | gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.zip gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.tar.gz gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.tar.bz2 |
libgo: Update to Go 1.1.1.
From-SVN: r200974
Diffstat (limited to 'libgo/go/syscall/sockcmsg_unix.go')
-rw-r--r-- | libgo/go/syscall/sockcmsg_unix.go | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/libgo/go/syscall/sockcmsg_unix.go b/libgo/go/syscall/sockcmsg_unix.go index 951bc18..03c1790 100644 --- a/libgo/go/syscall/sockcmsg_unix.go +++ b/libgo/go/syscall/sockcmsg_unix.go @@ -13,7 +13,7 @@ import ( "unsafe" ) -// Round the length of a raw sockaddr up to align it propery. +// Round the length of a raw sockaddr up to align it properly. func cmsgAlignOf(salen int) int { salign := int(sizeofPtr) // NOTE: It seems like 64-bit Darwin kernel still requires 32-bit @@ -26,9 +26,6 @@ func cmsgAlignOf(salen int) int { if runtime.GOOS == "solaris" { salign = 4 } - if salen == 0 { - return salign - } return (salen + salign - 1) & ^(salign - 1) } @@ -45,7 +42,7 @@ func CmsgSpace(datalen int) int { } func cmsgData(h *Cmsghdr) unsafe.Pointer { - return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + SizeofCmsghdr) + return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + uintptr(cmsgAlignOf(SizeofCmsghdr))) } // SocketControlMessage represents a socket control message. @@ -58,14 +55,15 @@ type SocketControlMessage struct { // messages. func ParseSocketControlMessage(b []byte) ([]SocketControlMessage, error) { var msgs []SocketControlMessage - for len(b) >= CmsgLen(0) { - h, dbuf, err := socketControlMessageHeaderAndData(b) + i := 0 + for i+CmsgLen(0) <= len(b) { + h, dbuf, err := socketControlMessageHeaderAndData(b[i:]) if err != nil { return nil, err } - m := SocketControlMessage{Header: *h, Data: dbuf[:int(h.Len)-cmsgAlignOf(SizeofCmsghdr)]} + m := SocketControlMessage{Header: *h, Data: dbuf} msgs = append(msgs, m) - b = b[cmsgAlignOf(int(h.Len)):] + i += cmsgAlignOf(int(h.Len)) } return msgs, nil } @@ -75,7 +73,7 @@ func socketControlMessageHeaderAndData(b []byte) (*Cmsghdr, []byte, error) { if h.Len < SizeofCmsghdr || int(h.Len) > len(b) { return nil, nil, EINVAL } - return h, b[cmsgAlignOf(SizeofCmsghdr):], nil + return h, b[cmsgAlignOf(SizeofCmsghdr):h.Len], nil } // UnixRights encodes a set of open file descriptors into a socket |