Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/acme: make Load more resilient in the face of a bad tag #78

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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