From 9685fc2b4d9d1e65a1253730f991421cd096535d Mon Sep 17 00:00:00 2001 From: Jayant Date: Wed, 13 Nov 2024 16:00:59 +0800 Subject: [PATCH] fix: deep copy nil string (#1562) --- tool/internal_pkg/pluginmode/thriftgo/struct_tpl.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tool/internal_pkg/pluginmode/thriftgo/struct_tpl.go b/tool/internal_pkg/pluginmode/thriftgo/struct_tpl.go index a3995e3214..b21491f5dc 100644 --- a/tool/internal_pkg/pluginmode/thriftgo/struct_tpl.go +++ b/tool/internal_pkg/pluginmode/thriftgo/struct_tpl.go @@ -713,16 +713,17 @@ const FieldDeepCopyBaseType = ` {{- if .IsPointer}} if {{$Src}} != nil { {{- if IsGoStringType .TypeName}} + var tmp string if *{{$Src}} != "" { - tmp := kutils.StringDeepCopy(*{{$Src}}) - {{.Target}} = &tmp + tmp = kutils.StringDeepCopy(*{{$Src}}) } + {{.Target}} = &tmp {{- else if .Type.Category.IsBinary}} + tmp := make([]byte, len(*{{$Src}})) if len(*{{$Src}}) != 0 { - tmp := make([]byte, len(*{{$Src}})) copy(tmp, *{{$Src}}) - {{.Target}} = &tmp } + {{.Target}} = &tmp {{- else}} tmp := *{{$Src}} {{.Target}} = &tmp