From 15a8ce8c0b97f9d5c7b3f81cb00d5a5150cf9387 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Mon, 24 Mar 2025 10:19:50 +0100 Subject: [PATCH] fix warnings by ineffassign, with a one actual issue In store/search.go, we would make a copy of a byte array, but then still use the original instead of the copy. Could result in search operations not finding messages that do have the content, but under very unlikely conditions only. We'll keep running ineffassign with "make check", useful enough. --- Makefile | 4 ++++ backup.go | 1 - develop.txt | 11 ++++++----- main.go | 4 ++-- queue/hook_test.go | 1 - queue/queue_test.go | 1 - smtpserver/server.go | 6 ++---- store/search.go | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 3dfceef..bb97fa4 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,9 @@ test-upgrade: build install-staticcheck: CGO_ENABLED=0 go install honnef.co/go/tools/cmd/staticcheck@latest +install-ineffassign: + CGO_ENABLED=0 go install github.com/gordonklaus/ineffassign@v0.1.0 + check: CGO_ENABLED=0 go vet -tags integration CGO_ENABLED=0 go vet -tags website website/website.go @@ -55,6 +58,7 @@ check: CGO_ENABLED=0 staticcheck -tags link rfc/link.go CGO_ENABLED=0 staticcheck -tags errata rfc/errata.go CGO_ENABLED=0 staticcheck -tags xr rfc/xr.go + CGO_ENABLED=0 ineffassign ./... # needed for check-shadow install-shadow: diff --git a/backup.go b/backup.go index 29a7c2c..f5e669e 100644 --- a/backup.go +++ b/backup.go @@ -512,7 +512,6 @@ func backupctl(ctx context.Context, ctl *ctl) { backupDB(db, jfpath) bloompath := filepath.Join("accounts", acc.Name, "junkfilter.bloom") backupFile(bloompath) - db = nil err := jf.Close() ctl.log.Check(err, "closing junkfilter") } diff --git a/develop.txt b/develop.txt index 3ebd418..7227417 100644 --- a/develop.txt +++ b/develop.txt @@ -13,11 +13,12 @@ code paths are reachable/testable with mox localserve, but some use cases will require a full setup. Before committing, run at least "make fmt" and "make check" (which requires -staticcheck, run "make install-staticcheck" once). Also run "make check-shadow" -and fix any shadowed variables other than "err" (which are filtered out, but -causes the command to always exit with an error code; run "make install-shadow" -once to install the shadow command). If you've updated RFC references, run -"make" in rfc/, it verifies the referenced files exist. +staticcheck and ineffassign, run "make install-staticcheck install-ineffassign" +once). Also run "make check-shadow" and fix any shadowed variables other than +"err" (which are filtered out, but causes the command to always exit with an +error code; run "make install-shadow" once to install the shadow command). If +you've updated RFC references, run "make" in rfc/, it verifies the referenced +files exist. When making changes to the public API of a package listed in apidiff/packages.txt, run "make genapidiff" to update the list of changes in diff --git a/main.go b/main.go index b3e03d6..f74dc5d 100644 --- a/main.go +++ b/main.go @@ -1960,11 +1960,12 @@ sharing most of its code. resolver := dns.StrictResolver{} var haveMX bool - var origNextHopAuthentic, expandedNextHopAuthentic bool + var expandedNextHopAuthentic bool var expandedNextHop dns.Domain var hosts []dns.IPDomain if len(args) == 1 { var permanent bool + var origNextHopAuthentic bool var err error haveMX, origNextHopAuthentic, expandedNextHopAuthentic, expandedNextHop, hosts, permanent, err = smtpclient.GatherDestinations(ctxbg, c.log.Logger, resolver, dns.IPDomain{Domain: origNextHop}) status := "temporary" @@ -1998,7 +1999,6 @@ sharing most of its code. d := xparseDomain(args[1], "destination host") log.Printf("skipping domain mx/cname lookups, assuming domain is dnssec-protected") - origNextHopAuthentic = true expandedNextHopAuthentic = true expandedNextHop = d hosts = []dns.IPDomain{{Domain: d}} diff --git a/queue/hook_test.go b/queue/hook_test.go index 802e40b..28459cb 100644 --- a/queue/hook_test.go +++ b/queue/hook_test.go @@ -656,7 +656,6 @@ func TestHookListFilterSort(t *testing.T) { var lr []HookRetired lastID = 0 last = "" - l = nil for { nl, err := HookRetiredList(ctxbg, HookRetiredFilter{Max: 1}, HookRetiredSort{LastID: lastID, Last: last}) tcheck(t, err, "list paginated") diff --git a/queue/queue_test.go b/queue/queue_test.go index a8dc3f4..23e815f 100644 --- a/queue/queue_test.go +++ b/queue/queue_test.go @@ -1435,7 +1435,6 @@ func TestListFilterSort(t *testing.T) { var lr []MsgRetired lastID = 0 last = "" - l = nil for { nl, err := RetiredList(ctxbg, RetiredFilter{Max: 1}, RetiredSort{LastID: lastID, Last: last}) tcheck(t, err, "list paginated") diff --git a/smtpserver/server.go b/smtpserver/server.go index 1bcb605..b451bc3 100644 --- a/smtpserver/server.go +++ b/smtpserver/server.go @@ -3424,18 +3424,16 @@ func (c *conn) deliver(ctx context.Context, recvHdrFor func(string) string, msgW return fmt.Errorf("finding rejects mailbox: %v", err) } - hasSpace := true if !conf.KeepRejects && mbrej != nil { - var chl []store.Change - chl, hasSpace, err = a.d.acc.TidyRejectsMailbox(c.log, tx, mbrej) + chl, hasSpace, err := a.d.acc.TidyRejectsMailbox(c.log, tx, mbrej) if err != nil { return fmt.Errorf("tidying rejects mailbox: %v", err) } + changes = append(changes, chl...) if !hasSpace { log.Info("not storing spammy mail to full rejects mailbox") return nil } - changes = append(changes, chl...) } if mbrej == nil { nmb, chl, _, _, err := a.d.acc.MailboxCreate(tx, conf.RejectsMailbox, store.SpecialUse{}) diff --git a/store/search.go b/store/search.go index ec4858a..969b664 100644 --- a/store/search.go +++ b/store/search.go @@ -187,7 +187,7 @@ func toLower(buf []byte) []byte { copied = true nr := make([]byte, len(r), len(r)+nsize+len(buf)-i) copy(nr, r) - nr = r + r = nr } r = utf8.AppendRune(r, nc) }