diff --git a/adapter/outbound/tuic.go b/adapter/outbound/tuic.go index 86b34dc8..c10a853a 100644 --- a/adapter/outbound/tuic.go +++ b/adapter/outbound/tuic.go @@ -162,7 +162,7 @@ func NewTuic(option TuicOption) (*Tuic, error) { tlsConfig = tlsC.GetGlobalTLSConfig(tlsConfig) } - if len(option.ALPN) > 0 { + if option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array tlsConfig.NextProtos = option.ALPN } else { tlsConfig.NextProtos = []string{"h3"} diff --git a/common/structure/structure.go b/common/structure/structure.go index 78f344a4..85254e24 100644 --- a/common/structure/structure.go +++ b/common/structure/structure.go @@ -282,6 +282,9 @@ func (d *Decoder) decodeSlice(name string, data any, val reflect.Value) error { } valSlice := val + // make a new slice with cap(val)==cap(dataVal) + // the caller can determine whether the original configuration contains this item by judging whether the value is nil. + valSlice = reflect.MakeSlice(valType, 0, dataVal.Len()) for i := 0; i < dataVal.Len(); i++ { currentData := dataVal.Index(i).Interface() for valSlice.Len() <= i {