Skip to content

Endless execution caused by MakeFunc. #19

@grumpyNeko

Description

@grumpyNeko

win10, amd64, go1.20.2

  1. define println0
  2. patch(stand, println0)
  3. patch(println0, redirector)
  4. call stand, expect it to jump to redirector

However, if redirector is defined by reflect.MakeFunc, step 4 seems to cause endless execution.

func println0() {
	println(0)
}

// -gcflags='all=-N -l'
func Test_bad(t *testing.T) {
	stand := reflect.MakeFunc(reflect.ValueOf(println0).Type(), nil)
	_, err := mpatch.PatchMethodByReflectValue(stand, println0) 
	if err != nil {
		panic(err.Error())
	}
	stand.Call(nil) // 0

	_, err = mpatch.PatchMethodByReflectValue(reflect.ValueOf(println0), reflect.MakeFunc(reflect.ValueOf(println0).Type(), func(args []reflect.Value) (results []reflect.Value) {
		println("redirector")
		return nil
	}))
	if err != nil {
		panic(err.Error())
	}
	stand.Call(nil) // endless 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions