Skip to content

Commit

Permalink
filters/diag/logbody: use correct calculation of bytes left to log (#…
Browse files Browse the repository at this point in the history
…2837)

Followup up on #2827

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Jan 9, 2024
1 parent cec514c commit b2bb841
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions filters/diag/logbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,12 @@ func newLogBodyStream(left int, f func([]byte), rc io.ReadCloser) io.ReadCloser
}

func (lb *logBodyStream) Read(p []byte) (n int, err error) {
if lb.left <= 0 {
return lb.input.Read(p)
}

n, err = lb.input.Read(p)
if n > 0 {
lb.f(p[:min(n, lb.left)])
if lb.left > 0 && n > 0 {
m := min(n, lb.left)
lb.f(p[:m])
lb.left -= m
}
lb.left -= n

return n, err
}

Expand Down

0 comments on commit b2bb841

Please sign in to comment.