]> Cypherpunks repositories - gostls13.git/commit
text/template: make reflect.Value indirections more robust
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 19 Dec 2019 14:13:59 +0000 (14:13 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Mon, 24 Feb 2020 09:16:18 +0000 (09:16 +0000)
commit218f4572f5d5832c81e13d71690791aea67dacd2
tree212a9614daf780f259e65102a955f1e4712011fc
parent31acdcc701cb97040832bce371fdd8985fbea131
text/template: make reflect.Value indirections more robust

Always shadow or modify the original parameter name. With code like:

func index(item reflect.Value, ... {
v := indirectInterface(item)

It was possible to incorrectly use 'item' and 'v' later in the function,
which could result in subtle bugs. This is precisely the kind of mistake
that led to #36199.

Instead, don't keep both the old and new reflect.Value variables in
scope. Always shadow or modify the original variable.

While at it, simplify the signature of 'length', to receive a
reflect.Value directly and save a few redundant lines.

Change-Id: I01416636a9d49f81246d28b91aca6413b1ba1aa5
Reviewed-on: https://go-review.googlesource.com/c/go/+/212117
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Roberto Clapis <robclap8@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
src/text/template/funcs.go