Skip to content

Commit 8fa163d

Browse files
committed
issue: fix nil pointer dereference on plumb error
plumbserve() fails with a nil pointer dereference when it tries to print errors via w.Err(). This happens because w is a dummy window with a nil *acme.Win. This commit replaces w.Err() calls in plumbserve() with log.Printf(). It also extracts the plumbserve() method out of *awin, given that the previous change removes this dependency. Fixes issue #5.
1 parent 7a65b24 commit 8fa163d

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

issue/acme.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,30 @@ func acmeMode() {
5959
dummy.Look("all")
6060
}
6161

62-
go dummy.plumbserve()
62+
go plumbserve()
6363

6464
select {}
6565
}
6666

67-
func (w *awin) plumbserve() {
67+
func plumbserve() {
6868
fid, err := plumb.Open("githubissue", 0)
6969
if err != nil {
70-
w.Err(fmt.Sprintf("plumb: %v", err))
70+
log.Printf("plumb: %v", err)
7171
return
7272
}
7373
r := bufio.NewReader(fid)
7474
for {
7575
var m plumb.Message
7676
if err := m.Recv(r); err != nil {
77-
w.Err(fmt.Sprintf("plumb recv: %v", err))
77+
log.Printf("plumb recv: %v", err)
7878
return
7979
}
8080
if m.Type != "text" {
81-
w.Err(fmt.Sprintf("plumb recv: unexpected type: %s\n", m.Type))
81+
log.Printf("plumb recv: unexpected type: %s", m.Type)
8282
continue
8383
}
8484
if m.Dst != "githubissue" {
85-
w.Err(fmt.Sprintf("plumb recv: unexpected dst: %s\n", m.Dst))
85+
log.Printf("plumb recv: unexpected dst: %s", m.Dst)
8686
continue
8787
}
8888
// TODO use m.Dir
@@ -92,26 +92,26 @@ func (w *awin) plumbserve() {
9292
project = data[len("/issue/"):]
9393
i := strings.LastIndex(project, "/")
9494
if i < 0 {
95-
w.Err(fmt.Sprintf("plumb recv: bad text %q", data))
95+
log.Printf("plumb recv: bad text %q", data)
9696
continue
9797
}
9898
project, what = project[:i], project[i+1:]
9999
} else {
100100
i := strings.Index(data, "#")
101101
if i < 0 {
102-
w.Err(fmt.Sprintf("plumb recv: bad text %q", data))
102+
log.Printf("plumb recv: bad text %q", data)
103103
continue
104104
}
105105
project, what = data[:i], data[i+1:]
106106
}
107107
if strings.Count(project, "/") != 1 {
108-
w.Err(fmt.Sprintf("plumb recv: bad text %q", data))
108+
log.Printf("plumb recv: bad text %q", data)
109109
continue
110110
}
111111
var plummy awin
112112
plummy.prefix = "/issue/" + project + "/"
113113
if !plummy.Look(what) {
114-
w.Err(fmt.Sprintf("plumb recv: can't look %s%s", plummy.prefix, what))
114+
log.Printf("plumb recv: can't look %s%s", plummy.prefix, what)
115115
}
116116
}
117117
}

0 commit comments

Comments
 (0)