-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: inconsistent behaviour of File's methods on a nil pointer #5824
Labels
Milestone
Comments
The change can only be made for methods that return an error, so Fd and Name are not candidates. The following program prints: Chdir panicked Chmod panicked Chown panicked Close panicked Readdir panicked Readdirnames panicked Seek panicked Stat panicked Truncate panicked package main import ( "fmt" "os" ) func test(name string, f func()){ defer func() { if recover() != nil { fmt.Println(name, "panicked") } }() f() } func main() { p := make([]byte, 10) test("Chdir", func(){(*os.File)(nil).Chdir()}) test("Chmod", func(){(*os.File)(nil).Chmod(0)}) test("Chown", func(){(*os.File)(nil).Chown(0, 0)}) test("Close", func(){(*os.File)(nil).Close()}) test("Read", func(){(*os.File)(nil).Read(p)}) test("ReadAt", func(){(*os.File)(nil).ReadAt(p, 0)}) test("Readdir", func(){(*os.File)(nil).Readdir(0)}) test("Readdirnames", func(){(*os.File)(nil).Readdirnames(0)}) test("Seek", func(){(*os.File)(nil).Seek(0, 0)}) test("Stat", func(){(*os.File)(nil).Stat()}) test("Sync", func(){(*os.File)(nil).Sync()}) test("Truncate", func(){(*os.File)(nil).Truncate(0)}) test("Write", func(){(*os.File)(nil).Write(p)}) test("WriteAt", func(){(*os.File)(nil).WriteAt(p, 0)}) test("WriteString", func(){(*os.File)(nil).WriteString("hi")}) } |
This issue was closed by revision 4cb086b. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by robryk:
The text was updated successfully, but these errors were encountered: