Skip to content

Commit

Permalink
zstd_stream.go: add explicit len() check
Browse files Browse the repository at this point in the history
  • Loading branch information
evanj committed Mar 8, 2021
1 parent 0ead11a commit ee09518
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion zstd_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ func (w *Writer) Write(p []byte) (int, error) {
srcData = w.srcBuffer
}

// &srcData[0] is safe: it is p or w.srcBuffer but only if len() > 0 checked above
if len(srcData) == 0 {
// this is technically unnecessary: srcData is p or w.srcBuffer, and len() > 0 checked above
// but this ensures the code can change without dereferencing an srcData[0]
return 0, nil
}
C.ZSTD_compressStream2_wrapper(
w.resultBuffer,
w.ctx,
Expand Down

0 comments on commit ee09518

Please sign in to comment.