summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-22 16:11:33 +0100
committerSimon Rozman <simon@rozman.si>2019-02-22 16:11:33 +0100
commite06a8f8f9f571598bd3afa84b006e24262dbc420 (patch)
tree884f2a2b53036f246e95fdb94d305e39b9feff2b
parentac4944a70855bdd869eb070bd80700e789024579 (diff)
wintun: Make two-step slicing a one step
Stop relying to Go compiler optimizations and calculate the end offset directly. Signed-off-by: Simon Rozman <simon@rozman.si>
-rw-r--r--tun/tun_windows.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go
index 137eb6c..65c32f2 100644
--- a/tun/tun_windows.go
+++ b/tun/tun_windows.go
@@ -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