Fix segfault when reading/writing from paster
parent
9e329458d6
commit
c72589bb7b
|
@ -66,12 +66,18 @@ func (p *Paster) prepareAndDo(buffer []byte, action func([]byte) (int, error)) (
|
|||
|
||||
// Read gets the contents of the paste from the filesystem
|
||||
func (p *Paster) Read(buffer []byte) (int, error) {
|
||||
return p.prepareAndDo(buffer, p.file.Read)
|
||||
// Wrap in closure to handle the nil file case
|
||||
return p.prepareAndDo(buffer, func(buffer []byte) (int, error) {
|
||||
return p.file.Read(buffer)
|
||||
})
|
||||
}
|
||||
|
||||
// Write sets the contents of the paste.
|
||||
func (p *Paster) Write(contents []byte) (int, error) {
|
||||
return p.prepareAndDo(contents, p.file.Write)
|
||||
// Wrap in closure to handle the nil file case
|
||||
return p.prepareAndDo(contents, func(buffer []byte) (int, error) {
|
||||
return p.file.Write(buffer)
|
||||
})
|
||||
}
|
||||
|
||||
// Close closes the paste
|
||||
|
|
Loading…
Reference in New Issue