From e216ee7e7416df48dc9550a6f18552a4ada5d419 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 9 Dec 2022 12:30:24 -0500 Subject: syscall: clean up variable declarations in forkAndExecInChild The various forkAndExecInChild implementations have comments explaining that they pre-declare variables to force allocations to occur before forking, but then later use ":=" declarations for additional variables. To make it clearer that those ":=" declarations do not allocate, we move their declarations up to the predeclared blocks. For #57208. Change-Id: Ie8cb577fa7180b51b64d6dc398169053fdf8ea97 Reviewed-on: https://go-review.googlesource.com/c/go/+/456516 Auto-Submit: Bryan Mills Reviewed-by: Ian Lance Taylor Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot --- src/syscall/exec_plan9.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/syscall/exec_plan9.go') diff --git a/src/syscall/exec_plan9.go b/src/syscall/exec_plan9.go index 8f28b5aa22..8762237825 100644 --- a/src/syscall/exec_plan9.go +++ b/src/syscall/exec_plan9.go @@ -135,6 +135,8 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at errbuf [ERRMAX]byte statbuf [STATMAX]byte dupdevfd int + n int + b []byte ) // Guard against side effects of shuffling fds below. @@ -177,14 +179,14 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at dirloop: for { r1, _, _ = RawSyscall6(SYS_PREAD, uintptr(dupdevfd), uintptr(unsafe.Pointer(&statbuf[0])), uintptr(len(statbuf)), ^uintptr(0), ^uintptr(0), 0) - n := int(r1) + n = int(r1) switch n { case -1: goto childerror case 0: break dirloop } - for b := statbuf[:n]; len(b) > 0; { + for b = statbuf[:n]; len(b) > 0; { var s []byte s, b = gdirname(b) if s == nil { -- cgit v1.3