From 8967adb2895fbcced9b00f8470265780e77b3dff Mon Sep 17 00:00:00 2001 From: tigerwill90 Date: Mon, 15 Jul 2024 19:26:44 +0200 Subject: [PATCH] feat: fix slice bound out of range due to incorrect usage of slice.Grow --- context.go | 2 +- tree.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/context.go b/context.go index 6ce1b65..4d74322 100644 --- a/context.go +++ b/context.go @@ -315,7 +315,7 @@ func (c *cTx) CloneWith(w ResponseWriter, r *http.Request) ContextCloser { cp.cachedQuery = nil if cap(*c.params) > cap(*cp.params) { // Grow cp.params to a least cap(c.params) - *cp.params = slices.Grow(*cp.params, cap(*c.params)-cap(*cp.params)) + *cp.params = slices.Grow(*cp.params, cap(*c.params)) } // cap(cp.params) >= cap(c.params) // now constraint into len(c.params) & cap(c.params) diff --git a/tree.go b/tree.go index 77d4d18..8c7b4aa 100644 --- a/tree.go +++ b/tree.go @@ -651,7 +651,7 @@ Walk: if !lazy { if cap(*c.params) > cap(*c.tsrParams) { // Grow c.tsrParams to a least cap(c.params) - *c.tsrParams = slices.Grow(*c.tsrParams, cap(*c.params)-cap(*c.tsrParams)) + *c.tsrParams = slices.Grow(*c.tsrParams, cap(*c.params)) } // cap(c.tsrParams) >= cap(c.params) // now constraint into len(c.params) & cap(c.params) @@ -693,7 +693,7 @@ Walk: if !lazy { if cap(*c.params) > cap(*c.tsrParams) { // Grow c.tsrParams to a least cap(c.params) - *c.tsrParams = slices.Grow(*c.tsrParams, cap(*c.params)-cap(*c.tsrParams)) + *c.tsrParams = slices.Grow(*c.tsrParams, cap(*c.params)) } // cap(c.tsrParams) >= cap(c.params) // now constraint into len(c.params) & cap(c.params) @@ -711,7 +711,7 @@ Walk: if !lazy { if cap(*c.params) > cap(*c.tsrParams) { // Grow c.tsrParams to a least cap(c.params) - *c.tsrParams = slices.Grow(*c.tsrParams, cap(*c.params)-cap(*c.tsrParams)) + *c.tsrParams = slices.Grow(*c.tsrParams, cap(*c.params)) } // cap(c.tsrParams) >= cap(c.params) // now constraint into len(c.params) & cap(c.params) @@ -752,7 +752,7 @@ Walk: if !lazy { if cap(*c.params) > cap(*c.tsrParams) { // Grow c.tsrParams to a least cap(c.params) - *c.tsrParams = slices.Grow(*c.tsrParams, cap(*c.params)-cap(*c.tsrParams)) + *c.tsrParams = slices.Grow(*c.tsrParams, cap(*c.params)) } // cap(c.tsrParams) >= cap(c.params) // now constraint into len(c.params) & cap(c.params)