aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text/template/exec.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2014-02-14 16:26:47 -0800
committerRob Pike <r@golang.org>2014-02-14 16:26:47 -0800
commit71575a97ab085695e1debd371fb3b33671cd810a (patch)
treeb540dd50f6fb44f1b7ec1f92ef3275ff94c389a1 /src/pkg/text/template/exec.go
parent881e23d36f0f814b1d5e5421987ccdf3d3a0b0cd (diff)
downloadgo-71575a97ab085695e1debd371fb3b33671cd810a.tar.xz
text/template: don't panic when function call evaluates a nil pointer
Catch the error instead and return it to the user. Before this fix, the template package panicked. Now you get: template: bug11:1:14: executing "bug11" at <.PS>: dereference of nil pointer of type *string Extended example at http://play.golang.org/p/uP6pCW3qKT Fixes #7333. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/64150043
Diffstat (limited to 'src/pkg/text/template/exec.go')
-rw-r--r--src/pkg/text/template/exec.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/pkg/text/template/exec.go b/src/pkg/text/template/exec.go
index 43b0b266ec..6de37a1996 100644
--- a/src/pkg/text/template/exec.go
+++ b/src/pkg/text/template/exec.go
@@ -594,6 +594,9 @@ func (s *state) validateType(value reflect.Value, typ reflect.Type) reflect.Valu
switch {
case value.Kind() == reflect.Ptr && value.Type().Elem().AssignableTo(typ):
value = value.Elem()
+ if !value.IsValid() {
+ s.errorf("dereference of nil pointer of type %s", typ)
+ }
case reflect.PtrTo(value.Type()).AssignableTo(typ) && value.CanAddr():
value = value.Addr()
default: