go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit 4b6cc33208fd6030808e5ebe3bdea30a2030d3f6
parent 59dcb7875db2a92718c8d049e8526e68012398f3
Author: lash <dev@holbrook.no>
Date:   Fri, 14 Apr 2023 09:09:53 +0100

Fix single byte overflow case for sized render

Diffstat:
Mengine/persist.go | 11-----------
Mengine/persist_test.go | 3+--
Mrender/page.go | 7+++----
Mrender/size.go | 1+
Mrender/size_test.go | 28++++++++++++++++++++++++++++
5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/engine/persist.go b/engine/persist.go @@ -3,7 +3,6 @@ package engine import ( "context" "io" - "log" "git.defalsify.org/festive/persist" "git.defalsify.org/festive/resource" @@ -30,17 +29,8 @@ func RunPersisted(cfg Config, rs resource.Resource, pr persist.Persister, input cfg.Root = location } - log.Printf("run persisted with state %v %x input %s", st, st.Code, input) en := NewEngine(cfg, pr.GetState(), rs, pr.GetMemory(), ctx) - log.Printf("location %s", location) - -// if len(input) == 0 { -// log.Printf("init") -// err = en.Init(location, ctx) -// if err != nil { -// return err -// } c, err := en.WriteResult(w, ctx) if err != nil { return err @@ -49,7 +39,6 @@ func RunPersisted(cfg Config, rs resource.Resource, pr persist.Persister, input if err != nil { return err } - log.Printf("engine init write %v flags %v", c, st.Flags) if c > 0 { return err } diff --git a/engine/persist_test.go b/engine/persist_test.go @@ -31,7 +31,6 @@ func TestPersist(t *testing.T) { ca := cache.NewCache().WithCacheSize(1024) pr := persist.NewFsPersister(persistDir).WithContent(&st, ca) - //w := bytes.NewBuffer(nil) w := os.Stdout ctx := context.TODO() @@ -46,7 +45,7 @@ func TestPersist(t *testing.T) { pr = persist.NewFsPersister(persistDir) inputs := []string{ - "", + "", // trigger init, will not exec "1", "2", "00", diff --git a/render/page.go b/render/page.go @@ -251,16 +251,15 @@ func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[st tb := strings.Builder{} rb := strings.Builder{} - netRemaining := remaining + netRemaining := remaining - 1 if len(sinkValues) > 1 { - log.Printf("menusizes %v", menuSizes) netRemaining -= menuSizes[1] - 1 } for i, v := range sinkValues { - log.Printf("processing sinkvalue %v: %s", i, v) l += len(v) - if uint32(l) > netRemaining { + log.Printf("processing sinkvalue %v: %s", i, v) + if uint32(l) > netRemaining - 1 { if tb.Len() == 0 { return nil, fmt.Errorf("capacity insufficient for sink field %v", i) } diff --git a/render/size.go b/render/size.go @@ -47,6 +47,7 @@ func(szr *Sizer) Check(s string) (uint32, bool) { if szr.outputSize > 0 { if l > szr.outputSize { log.Printf("sizer check fails with length %v: %s", l, szr) + log.Printf("sizer contents:\n%s", s) return 0, false } l = szr.outputSize - l diff --git a/render/size_test.go b/render/size_test.go @@ -192,3 +192,31 @@ eleven twelve } } + +func TestManySizes(t *testing.T) { + for i := 50; i < 128; i++ { + st := state.NewState(0) + ca := cache.NewCache() + mn := NewMenu().WithOutputSize(32) + mrs := resource.NewMenuResource().WithEntryFuncGetter(funcFor).WithTemplateGetter(getTemplate) + rs := TestSizeResource{ + mrs, + } + szr := NewSizer(uint32(i)) + pg := NewPage(ca, rs).WithSizer(szr).WithMenu(mn) + ca.Push() + st.Down("pages") + ca.Add("foo", "inky", 10) + ca.Add("bar", "pinky", 10) + ca.Add("baz", "blinky", 10) + ca.Add("xyzzy", "inky pinky\nblinky clyde sue\ntinkywinky dipsy\nlala poo\none two three four five six seven\neight nine ten\neleven twelve", 0) + pg.Map("foo") + pg.Map("bar") + pg.Map("baz") + pg.Map("xyzzy") + _, err := pg.Render("pages", 0) + if err != nil { + t.Fatal(err) + } + } +}