From 1f5c8ce353e48b7eccb37d0d8f214cf24610957d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 29 Feb 2024 01:15:08 +0100 Subject: [PATCH] Don't mix up capacity and length - `make([]a, b)` create a slice of `b` elements `a` - `make([]a, b, c)` create a slice of `0` elements `a`, but reserve space for `c` of them When using `append` on the former, it will result on a slice with `b` leading elements, which is unlikely to be what we want. This commit replaces the two instances where this happens with the latter construct. --- internal/googlereader/handler.go | 2 +- internal/storage/enclosure.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/googlereader/handler.go b/internal/googlereader/handler.go index df3205c0..488eaebc 100644 --- a/internal/googlereader/handler.go +++ b/internal/googlereader/handler.go @@ -984,7 +984,7 @@ func (h *handler) streamItemContentsHandler(w http.ResponseWriter, r *http.Reque } contentItems := make([]contentItem, len(entries)) for i, entry := range entries { - enclosures := make([]contentItemEnclosure, len(entry.Enclosures)) + enclosures := make([]contentItemEnclosure, 0, len(entry.Enclosures)) for _, enclosure := range entry.Enclosures { enclosures = append(enclosures, contentItemEnclosure{URL: enclosure.URL, Type: enclosure.MimeType}) } diff --git a/internal/storage/enclosure.go b/internal/storage/enclosure.go index 197ae577..1f3a832b 100644 --- a/internal/storage/enclosure.go +++ b/internal/storage/enclosure.go @@ -132,7 +132,7 @@ func (s *Storage) updateEnclosures(tx *sql.Tx, entry *model.Entry) error { return nil } - sqlValues := make([]string, len(entry.Enclosures)) + sqlValues := make([]string, 0, len(entry.Enclosures)) for _, enclosure := range entry.Enclosures { sqlValues = append(sqlValues, strings.TrimSpace(enclosure.URL))