Skip to content

Commit

Permalink
Merge pull request #3 from danp/ensure-bounds
Browse files Browse the repository at this point in the history
ensure copy of p when Writing stays within bounds
  • Loading branch information
djherbis committed Jan 17, 2017
2 parents a376bfc + af59e95 commit ef1ef18
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,14 @@ func (w *PipeWriter) Write(p []byte) (n int, err error) {
w.c.Wait()
}

// chunk write to fill space
m, err = w.b.Write(p[n : int64(n)+gap(w.b)])
// now that we have the lock, see what the real gap is
nn := int64(n) + gap(w.b)
if nn > int64(len(p)) {
// it's grown enough, just do a standard write
break
}

m, err = w.b.Write(p[n:nn])
n += m
if err != nil {
return n, err
Expand Down

0 comments on commit ef1ef18

Please sign in to comment.