From cf201ed6a00223e1e6dd69e884f9bcd25ce2b62c Mon Sep 17 00:00:00 2001 From: Graham Miller Date: Mon, 20 Jun 2011 15:42:17 -0400 Subject: [PATCH] os: change Waitmsg String method to use pointer receiver Fixes #1851. R=rsc CC=golang-dev https://golang.org/cl/4628045 --- src/pkg/os/exec_plan9.go | 5 ++++- src/pkg/os/exec_posix.go | 5 ++++- src/pkg/os/os_test.go | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pkg/os/exec_plan9.go b/src/pkg/os/exec_plan9.go index 0598adc0fa1..2590dd67de2 100644 --- a/src/pkg/os/exec_plan9.go +++ b/src/pkg/os/exec_plan9.go @@ -123,6 +123,9 @@ func FindProcess(pid int) (p *Process, err Error) { return newProcess(pid, 0), nil } -func (w Waitmsg) String() string { +func (w *Waitmsg) String() string { + if w == nil { + return "" + } return "exit status: " + w.Msg } diff --git a/src/pkg/os/exec_posix.go b/src/pkg/os/exec_posix.go index 734bf887b39..7dfcdd48615 100644 --- a/src/pkg/os/exec_posix.go +++ b/src/pkg/os/exec_posix.go @@ -128,7 +128,10 @@ func itod(i int) string { return string(b[bp:]) } -func (w Waitmsg) String() string { +func (w *Waitmsg) String() string { + if w == nil { + return "" + } // TODO(austin) Use signal names when possible? res := "" switch { diff --git a/src/pkg/os/os_test.go b/src/pkg/os/os_test.go index e442e7c28a6..c22b536d557 100644 --- a/src/pkg/os/os_test.go +++ b/src/pkg/os/os_test.go @@ -1042,3 +1042,11 @@ func TestStatDirWithTrailingSlash(t *testing.T) { t.Fatal("stat failed:", err) } } + +func TestNilWaitmsgString(t *testing.T) { + var w *Waitmsg + s := w.String() + if s != "" { + t.Errorf("(*Waitmsg)(nil).String() = %q, want %q", s, "") + } +}