]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
wintun: Make two-step slicing a one step
authorSimon Rozman <simon@rozman.si>
Fri, 22 Feb 2019 15:11:33 +0000 (16:11 +0100)
committerSimon Rozman <simon@rozman.si>
Fri, 22 Feb 2019 15:11:33 +0000 (16:11 +0100)
Stop relying to Go compiler optimizations and calculate the end offset
directly.

Signed-off-by: Simon Rozman <simon@rozman.si>
tun/tun_windows.go

index 137eb6cf6058cca711b486897b334841722334ec..65c32f21569b831880f682ae71c263944a8c596a 100644 (file)
@@ -240,7 +240,7 @@ func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
                        packet = packet[:pSize]
 
                        // Copy data.
-                       copy(buff[offset:], packet[packetExchangeAlignment:][:size])
+                       copy(buff[offset:], packet[packetExchangeAlignment:packetExchangeAlignment+size])
                        tun.rdBuff.offset += pSize
                        return int(size), nil
                }
@@ -331,9 +331,9 @@ func (tun *nativeTun) putTunPacket(buff []byte) error {
        }
 
        // Write packet to the exchange buffer.
-       packet := tun.wrBuff.data[tun.wrBuff.offset:][:pSize]
+       packet := tun.wrBuff.data[tun.wrBuff.offset : tun.wrBuff.offset+pSize]
        binary.LittleEndian.PutUint32(packet[:4], size)
-       copy(packet[packetExchangeAlignment:][:size], buff)
+       copy(packet[packetExchangeAlignment:packetExchangeAlignment+size], buff)
 
        tun.wrBuff.packetNum++
        tun.wrBuff.offset += pSize