From 5674fbff976edb6ec607bf28de9093318bd746d2 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Tue, 2 Nov 2021 11:42:45 +0000 Subject: [PATCH] cmd/acme: make Load more resilient in the face of a bad tag See https://github.com/9fans/go/issues/68. --- cmd/acme/internal/dump/rows1.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/acme/internal/dump/rows1.go b/cmd/acme/internal/dump/rows1.go index 6c81496..0f07bca 100644 --- a/cmd/acme/internal/dump/rows1.go +++ b/cmd/acme/internal/dump/rows1.go @@ -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 @@ -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 @@ -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()))