Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why is null in Go unsafe?


    res, err := http.Get("wcpgw")
    defer res.Body.Close()

    ...

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x5ed9af]


Presumably because there’s no language-level way to guarantee a pointer to be non-nil at compile time, combined with nil dereferencing being a crash. Not unsafe in the security sense, but definitely unsafe in the “can I count on my program to run” sense.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: