From 51a2418f38fb285c57da238a2ba523c6f6684a9a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 22 Feb 2024 22:03:50 +0100 Subject: [PATCH] net: use bytealg.IndexByte in cgoLookupAddrPTR Change-Id: I76f4dc1e8bda98936c1198cb45ce8141ca88845b Reviewed-on: https://go-review.googlesource.com/c/go/+/566235 Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Carlos Amedee Auto-Submit: Tobias Klauser LUCI-TryBot-Result: Go LUCI --- src/net/cgo_unix.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/net/cgo_unix.go b/src/net/cgo_unix.go index 82ec4441fc..0f62fdeb11 100644 --- a/src/net/cgo_unix.go +++ b/src/net/cgo_unix.go @@ -14,6 +14,7 @@ package net import ( "context" "errors" + "internal/bytealg" "net/netip" "syscall" "unsafe" @@ -287,11 +288,8 @@ func cgoLookupAddrPTR(addr string, sa *_C_struct_sockaddr, salen _C_socklen_t) ( } return nil, &DNSError{Err: err.Error(), Name: addr, IsTemporary: isTemporary, IsNotFound: isErrorNoSuchHost} } - for i := 0; i < len(b); i++ { - if b[i] == 0 { - b = b[:i] - break - } + if i := bytealg.IndexByte(b, 0); i != -1 { + b = b[:i] } return []string{absDomainName(string(b))}, nil } -- 2.50.0