]> Cypherpunks repositories - gostls13.git/commitdiff
os: change Waitmsg String method to use pointer receiver
authorGraham Miller <graham.miller@gmail.com>
Mon, 20 Jun 2011 19:42:17 +0000 (15:42 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 20 Jun 2011 19:42:17 +0000 (15:42 -0400)
Fixes #1851.

R=rsc
CC=golang-dev
https://golang.org/cl/4628045

src/pkg/os/exec_plan9.go
src/pkg/os/exec_posix.go
src/pkg/os/os_test.go

index 0598adc0fa1cc3e46f3e612281de5b6dea60285b..2590dd67de2a5882593d69f169f75112e5736e5d 100644 (file)
@@ -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 "<nil>"
+       }
        return "exit status: " + w.Msg
 }
index 734bf887b393bcb6158dc32e89bdc1484d583025..7dfcdd48615b97940f414652cf6e8fa5adccc41b 100644 (file)
@@ -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 "<nil>"
+       }
        // TODO(austin) Use signal names when possible?
        res := ""
        switch {
index e442e7c28a64e4973cc009f3718aefe456b6320a..c22b536d55734aae7bb88ab6bec31110d3c7a34b 100644 (file)
@@ -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 != "<nil>" {
+               t.Errorf("(*Waitmsg)(nil).String() = %q, want %q", s, "<nil>")
+       }
+}