Fix lint errors

This commit is contained in:
世界 2026-07-16 18:45:49 +08:00
parent 994d6ccdbf
commit d1af8aaf7e
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 15 additions and 21 deletions

View file

@ -22,7 +22,6 @@ import (
"github.com/sagernet/sing-tun/gtcpip"
"github.com/sagernet/sing-tun/gtcpip/checksum"
"github.com/sagernet/sing/common"
)
// RFC 971 defines the fields of the IPv4 header on page 11 using the following
@ -335,7 +334,7 @@ func (b IPv4) FragmentOffset() uint16 {
}
func (b IPv4) FragmentOffsetDarwinRaw() uint16 {
return common.NativeEndian.Uint16(b[flagsFO:]) << 3
return binary.NativeEndian.Uint16(b[flagsFO:]) << 3
}
// TotalLength returns the "total length" field of the IPv4 header.
@ -344,7 +343,7 @@ func (b IPv4) TotalLength() uint16 {
}
func (b IPv4) TotalLengthDarwinRaw() uint16 {
return common.NativeEndian.Uint16(b[IPv4TotalLenOffset:]) + uint16(b.HeaderLength())
return binary.NativeEndian.Uint16(b[IPv4TotalLenOffset:]) + uint16(b.HeaderLength())
}
// Checksum returns the checksum field of the IPv4 header.
@ -441,7 +440,7 @@ func (b IPv4) SetTotalLength(totalLength uint16) {
}
func (b IPv4) SetTotalLengthDarwinRaw(totalLength uint16) {
common.NativeEndian.PutUint16(b[IPv4TotalLenOffset:], totalLength)
binary.NativeEndian.PutUint16(b[IPv4TotalLenOffset:], totalLength)
}
// SetChecksum sets the checksum field of the IPv4 header.
@ -458,7 +457,7 @@ func (b IPv4) SetFlagsFragmentOffset(flags uint8, offset uint16) {
func (b IPv4) SetFlagsFragmentOffsetDarwinRaw(flags uint8, offset uint16) {
v := (uint16(flags) << 13) | (offset >> 3)
common.NativeEndian.PutUint16(b[flagsFO:], v)
binary.NativeEndian.PutUint16(b[flagsFO:], v)
}
// SetID sets the identification field.
@ -1179,7 +1178,7 @@ func (s IPv4OptionsSerializer) Serialize(b []byte) uint8 {
// header ends on a 32 bit boundary. The padding is zero.
padded := padIPv4OptionsLength(total)
b = b[:padded-total]
common.ClearArray(b)
clear(b)
return padded
}

View file

@ -21,7 +21,6 @@ import (
"math"
"github.com/sagernet/sing-tun/gtcpip"
"github.com/sagernet/sing/common"
)
// IPv6ExtensionHeaderIdentifier is an IPv6 extension header identifier.
@ -129,7 +128,7 @@ func padIPv6Option(b []byte) {
b[ipv6ExtHdrOptionTypeOffset] = uint8(ipv6Pad1ExtHdrOptionIdentifier)
default: // Pad with PadN.
s := b[ipv6ExtHdrOptionPayloadOffset:]
common.ClearArray(s)
clear(s)
b[ipv6ExtHdrOptionTypeOffset] = uint8(ipv6PadNExtHdrOptionIdentifier)
b[ipv6ExtHdrOptionLengthOffset] = uint8(len(s))
}

View file

@ -24,7 +24,6 @@ import (
"time"
"github.com/sagernet/sing-tun/gtcpip"
"github.com/sagernet/sing/common"
)
// ndpOptionIdentifier is an NDP option type identifier.
@ -341,7 +340,7 @@ func (b NDPOptions) Serialize(s NDPOptionsSerializer) int {
// Zero out remaining (padding) bytes, if any exists.
if used+2 < l {
common.ClearArray(b[used+2 : l])
clear(b[used+2 : l])
}
b = b[l:]
@ -567,7 +566,7 @@ func (o NDPPrefixInformation) serializeInto(b []byte) int {
// Zero out the Reserved2 field.
reserved2 := b[ndpPrefixInformationReserved2Offset:][:ndpPrefixInformationReserved2Length]
common.ClearArray(reserved2)
clear(reserved2)
return used
}
@ -686,7 +685,7 @@ func (o NDPRecursiveDNSServer) serializeInto(b []byte) int {
used := copy(b, o)
// Zero out the reserved bytes that are before the Lifetime field.
common.ClearArray(b[0:ndpRecursiveDNSServerLifetimeOffset])
clear(b[0:ndpRecursiveDNSServerLifetimeOffset])
return used
}
@ -779,7 +778,7 @@ func (o NDPDNSSearchList) serializeInto(b []byte) int {
used := copy(b, o)
// Zero out the reserved bytes that are before the Lifetime field.
common.ClearArray(b[0:ndpDNSSearchListLifetimeOffset])
clear(b[0:ndpDNSSearchListLifetimeOffset])
return used
}

View file

@ -50,7 +50,6 @@ import (
"github.com/sagernet/gvisor/pkg/tcpip/header"
"github.com/sagernet/gvisor/pkg/tcpip/stack"
rawfile "github.com/sagernet/sing-tun/internal/rawfile_darwin"
"github.com/sagernet/sing/common"
"golang.org/x/sys/unix"
)
@ -301,7 +300,7 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
e.fds = append(e.fds, fdInfo{fd: fd, isSocket: true})
if opts.ProcessorsPerChannel == 0 {
opts.ProcessorsPerChannel = common.Max(1, runtime.GOMAXPROCS(0)/len(opts.FDs))
opts.ProcessorsPerChannel = max(1, runtime.GOMAXPROCS(0)/len(opts.FDs))
}
inboundDispatcher, err := newRecvMMsgDispatcher(fd, e, opts)

View file

@ -1,11 +1,10 @@
package ping
import (
"encoding/binary"
"fmt"
"unsafe"
"github.com/sagernet/sing/common"
"golang.org/x/net/ipv6"
"golang.org/x/sys/windows"
)
@ -37,9 +36,9 @@ func parseIPv6ControlMessage(cmsg []byte) (*ipv6.ControlMessage, error) {
}
switch cmsghdr.Type {
case IPV6_TCLASS:
controlMessage.TrafficClass = int(common.NativeEndian.Uint32(cmsg[alignedSizeofCmsghdr : alignedSizeofCmsghdr+4]))
controlMessage.TrafficClass = int(binary.NativeEndian.Uint32(cmsg[alignedSizeofCmsghdr : alignedSizeofCmsghdr+4]))
case IPV6_HOPLIMIT:
controlMessage.HopLimit = int(common.NativeEndian.Uint32(cmsg[alignedSizeofCmsghdr : alignedSizeofCmsghdr+4]))
controlMessage.HopLimit = int(binary.NativeEndian.Uint32(cmsg[alignedSizeofCmsghdr : alignedSizeofCmsghdr+4]))
}
cmsg = cmsg[msgSize:]
}

View file

@ -9,7 +9,6 @@ import (
"time"
"github.com/sagernet/sing-tun/gtcpip/header"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf"
"github.com/sagernet/sing/common/control"
M "github.com/sagernet/sing/common/metadata"
@ -175,7 +174,7 @@ func (c *UnprivilegedConn) Close() error {
for _, conn := range c.mapping {
_ = conn.Close()
}
common.ClearMap(c.mapping)
clear(c.mapping)
return nil
}