Casting uintptr as upointer is haram. You must read the rules: https://golang.org/pkg/unsafe/#Pointer
But there's hacky way, that shouldn't produce warning:
//go:linkname gostringn runtime.gostringn func gostringn(p uintptr, l int) string //go:linkname findnull runtime.findnull //go:nosplit func findnull(s uintptr) int // .... name := gostringn(r, findnull(r))
Functions takes pointer, but we link them from runtime as uintptr because they have same sizeof.
Might work in theory. But is also frowned upon.
Getting back to your code, as JimB said, you could do it one line with:
name := C.GoString((*C.char)(unsafe.Pointer(r)))