From 27420a3fb37d1d51c796043794f1ea70c1a7bc98 Mon Sep 17 00:00:00 2001 From: jz Date: Tue, 9 Aug 2016 15:15:11 -0700 Subject: [PATCH] Change decoder to write to pointer memory if not null --- gen/decoder.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gen/decoder.go b/gen/decoder.go index 94c1a9a..dd1187f 100644 --- a/gen/decoder.go +++ b/gen/decoder.go @@ -118,7 +118,9 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field fmt.Fprintln(g.out, ws+" in.Skip()") fmt.Fprintln(g.out, ws+" "+out+" = nil") fmt.Fprintln(g.out, ws+"} else {") - fmt.Fprintln(g.out, ws+" "+out+" = new("+g.getType(t.Elem())+")") + fmt.Fprintln(g.out, ws+" if ("+out+") == nil {") + fmt.Fprintln(g.out, ws+" "+out+" = new("+g.getType(t.Elem())+")") + fmt.Fprintln(g.out, ws+" }") g.genTypeDecoder(t.Elem(), "*"+out, tags, indent+1)