Skip to contentSkip to conversation

tun: use ByteSliceToString from golang.org/x/sys/unix

PATCH Applied Tobias Klauser 2 participants 3 messages Jun 1, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tun: use ByteSliceToString from golang.org/x/sys/unix

Use unix.ByteSliceToString in (*NativeTun).nameSloce to convert the TUNGETIFF ioctl result []byte to a string.

---
 tun/tun_linux.go | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
tun/tun_linux.go +1 -6
index 89b716d9c70b..fbb8585ff449 100644
@@ -9,7 +9,6 @@ package tun
  */
 
 import (
-	"bytes"
 	"errors"
 	"fmt"
 	"os"
@@ -321,11 +320,7 @@ func (tun *NativeTun) nameSlow() (string, error) {
 	if errno != 0 {
 		return "", fmt.Errorf("failed to get name of TUN device: %w", errno)
 	}
-	name := ifr[:]
-	if i := bytes.IndexByte(name, 0); i != -1 {
-		name = name[:i]
-	}
-	return string(name), nil
+	return unix.ByteSliceToString(ifr[:]), nil
 }
 
 func (tun *NativeTun) Write(buf []byte, offset int) (int, error) {
Signature · 1 line
2.36.1
#1 lore raw
Quoted 1 line · Tobias Klauser

Use unix.ByteSliceToString in (*NativeTun).nameSloce to convert the

^- this should say nameSlow

I can fix it up in a v2 patch if needed.