Skip to content

Commit

Permalink
cmd/acme: make Load more resilient in the face of a bad tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rogpeppe committed Nov 4, 2021
1 parent 0f92e5c commit 5674fbf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/acme/internal/dump/rows1.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func Dump(row *wind.Row, file *string) {
b.WriteString(wind.Winctlprint(w, false))
m = util.Min(bufs.RuneLen, w.Tag.Len())
w.Tag.File.Read(0, r[:m])
if !containsRune(r[:m], '|') {
alog.Printf("dump: window %d has no | in tag %q!", w.ID, string(r[:m]))
}
n = 0
for n < m {
start := n
Expand Down Expand Up @@ -180,6 +183,15 @@ func Dump(row *wind.Row, file *string) {
bufs.FreeRunes(r)
}

func containsRune(r []rune, c rune) bool {
for _, rc := range r {
if rc == c {
return true
}
}
return false
}

func exists(file string) bool {
_, err := os.Stat(file)
return err == nil
Expand Down Expand Up @@ -476,7 +488,11 @@ func Load(row *wind.Row, file *string, initing bool) bool {
}
}
wind.Wincleartatg(w)
wind.Textinsert(&w.Tag, w.Tag.Len(), r[n+1:], true)
if n < len(r) {
wind.Textinsert(&w.Tag, w.Tag.Len(), r[n+1:], true)
} else {
alog.Printf("load: found window tag with no | character (tag: %q)", string(r))
}
if ndumped >= 0 {
// simplest thing is to put it in a file and load that
f, err := ioutil.TempFile("", fmt.Sprintf("acme.%d.*", os.Getpid()))
Expand Down

0 comments on commit 5674fbf

Please sign in to comment.