Skip to content

unsafe.Pointer(nil) doesn't convert correctly to other pointer types. #1060

@nevkontakte

Description

@nevkontakte

GopherJS's zero value for unsafe.Pointer is a numeric 0 (I'm guessing for interop with uintptr, but not entirely sure). However, this is incompatible with a pointer interface and causes incorrect behavior when converted into another pointer type:

package main

import (
	"unsafe"
)

func main() {
	var up unsafe.Pointer

	p := (*bool)(up)
	if p != nil {
		println("error: p should be nil")
	}
	println("not nil", *p)
}

By contrast, if up is initialized with unsafe.Pointer((*bool)(nil)), the program works correctly.

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