Skip to content

Commit

Permalink
avoid overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Aug 19, 2024
1 parent a6641ec commit 6fddae5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bigfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,14 @@ func (c *flateWriter) shouldCall() bool {
// 聚合写入, 减少syscall.write调用次数
// Aggregate writes, reducing the number of syscall.write calls
func (c *flateWriter) write(p []byte) {
var size = internal.Max(segmentSize, len(p))
if len(c.buffers) == 0 {
c.buffers = append(c.buffers, binaryPool.Get(segmentSize))
c.buffers = append(c.buffers, binaryPool.Get(size))
}
var n = len(c.buffers)
var tail = c.buffers[n-1]
if tail.Len()+len(p)+frameHeaderSize > tail.Cap() {
tail = binaryPool.Get(segmentSize)
tail = binaryPool.Get(size)
c.buffers = append(c.buffers, tail)
}
tail.Write(p)
Expand Down

0 comments on commit 6fddae5

Please sign in to comment.