From d1777c5fda57f01808213af9d86406b31737be91 Mon Sep 17 00:00:00 2001 From: Aaron Gable Date: Wed, 16 Feb 2022 14:33:17 -0800 Subject: [PATCH] Fix shadowing assignments inside closures (#5944) When inside a closure, it is important to not accidentally assign to variables declared outside the scope of the closure. Doing so causes static analysis tools (such as `errcheck`) to be unable to evaluate the lifetime of the variable, and unable to determine if it is appropriately read from before being assigned to again. Fix two instances where we assign to a variable declared in the closure's enclosing scope, rather than declaring a new variable with the same name. --- rocsp/rocsp.go | 2 +- test/ocsp/ocsp_forever/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rocsp/rocsp.go b/rocsp/rocsp.go index dbc11e88d..c54e18ba1 100644 --- a/rocsp/rocsp.go +++ b/rocsp/rocsp.go @@ -189,7 +189,7 @@ func (c *WritingClient) StoreResponse(ctx context.Context, respBytes []byte, sho metadataValue := metadataStruct.Marshal() err = c.rdb.Watch(ctx, func(tx *redis.Tx) error { - err = tx.Set(ctx, responseKey, respBytes, ttl).Err() + err := tx.Set(ctx, responseKey, respBytes, ttl).Err() if err != nil { return fmt.Errorf("setting response: %w", err) } diff --git a/test/ocsp/ocsp_forever/main.go b/test/ocsp/ocsp_forever/main.go index a716a9c91..f559c133f 100644 --- a/test/ocsp/ocsp_forever/main.go +++ b/test/ocsp/ocsp_forever/main.go @@ -80,7 +80,7 @@ func main() { } http.Handle("/metrics", promhttp.Handler()) go func() { - err = http.ListenAndServe(*listenAddress, nil) + err := http.ListenAndServe(*listenAddress, nil) if err != nil && err != http.ErrServerClosed { log.Fatal(err) }