From abdec5abdab0b28aef6daa65daac73163e41f6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 4 Jan 2025 22:38:01 +0000 Subject: [PATCH] assume obj is non-nil in obfuscatedObjectName Only two callers did pass nil, and there's no reason for them to do so. They should be the ones to check that typeToObj did not return nil. --- reflect.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/reflect.go b/reflect.go index 7233e24..93f9bb0 100644 --- a/reflect.go +++ b/reflect.go @@ -189,13 +189,13 @@ func (ri *reflectInspector) checkFunction(fun *ssa.Function) { switch inst := inst.(type) { case *ssa.Store: obj := typeToObj(inst.Addr.Type()) - if usedForReflect(ri.result, obj) { + if obj != nil && usedForReflect(ri.result, obj) { ri.recordArgReflected(inst.Val, make(map[ssa.Value]bool)) ri.propagatedInstr[inst] = true } case *ssa.ChangeType: obj := typeToObj(inst.X.Type()) - if usedForReflect(ri.result, obj) { + if obj != nil && usedForReflect(ri.result, obj) { ri.recursivelyRecordUsedForReflect(inst.Type(), nil) ri.propagatedInstr[inst] = true } @@ -467,12 +467,9 @@ func recordedObjectString(obj types.Object) objectString { // obfuscatedObjectName returns the obfucated name of a types.Object, // parent is needed to correctly get the obfucated name of struct fields func obfuscatedObjectName(obj types.Object, parent *types.Struct) string { - if obj == nil { - return "" - } pkg := obj.Pkg() if pkg == nil { - return "" + return "" // builtin types are never obfuscated } if v, ok := obj.(*types.Var); ok && parent != nil {