mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: be consistent about File methods with nil receivers
Some crashed, some didn't. Make a nil receiver always return ErrInvalid rather than crash. Fixes #5824. The program in the bug listing is silent now, at least on my Mac. R=golang-dev, adg CC=golang-dev https://golang.org/cl/13108044
This commit is contained in:
parent
a3695fb227
commit
4cb086b838
7 changed files with 49 additions and 1 deletions
|
|
@ -96,6 +96,9 @@ func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
|
|||
// Close closes the File, rendering it unusable for I/O.
|
||||
// It returns an error, if any.
|
||||
func (f *File) Close() error {
|
||||
if f == nil {
|
||||
return ErrInvalid
|
||||
}
|
||||
return f.file.close()
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +120,9 @@ func (file *file) close() error {
|
|||
// Stat returns the FileInfo structure describing file.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func (f *File) Stat() (fi FileInfo, err error) {
|
||||
if f == nil {
|
||||
return nil, ErrInvalid
|
||||
}
|
||||
var stat syscall.Stat_t
|
||||
err = syscall.Fstat(f.fd, &stat)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue