зеркало из https://github.com/github/vitess-gh.git
handle empty slices properly
This commit is contained in:
Родитель
608cfa8ec6
Коммит
6bc0fbd682
|
@ -30,7 +30,9 @@ func NewAdler32() hash.Hash32 {
|
|||
|
||||
// io.Writer interface
|
||||
func (a *adler32Hash) Write(p []byte) (n int, err error) {
|
||||
a.adler = C.adler32(a.adler, (*C.Bytef)(unsafe.Pointer(&p[0])), (C.uInt)(len(p)))
|
||||
if len(p) > 0 {
|
||||
a.adler = C.adler32(a.adler, (*C.Bytef)(unsafe.Pointer(&p[0])), (C.uInt)(len(p)))
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,9 @@ func NewCrc32() hash.Hash32 {
|
|||
|
||||
// io.Writer interface
|
||||
func (a *crc32Hash) Write(p []byte) (n int, err error) {
|
||||
a.crc = C.crc32(a.crc, (*C.Bytef)(unsafe.Pointer(&p[0])), (C.uInt)(len(p)))
|
||||
if len(p) > 0 {
|
||||
a.crc = C.crc32(a.crc, (*C.Bytef)(unsafe.Pointer(&p[0])), (C.uInt)(len(p)))
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,10 @@ func (z *reader) Read(p []byte) (int, error) {
|
|||
return 0, z.err
|
||||
}
|
||||
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// read and deflate until the output buffer is full
|
||||
z.strm.next_out = (*C.Bytef)(unsafe.Pointer(&p[0]))
|
||||
z.strm.avail_out = (C.uInt)(len(p))
|
||||
|
|
|
@ -95,7 +95,7 @@ func NewWriterLevelBuffer(w io.Writer, level, bufferSize int) (*Writer, error) {
|
|||
// this is the main function: it advances the write with either
|
||||
// new data or something else to do, like a flush
|
||||
func (z *Writer) write(p []byte, flush int) int {
|
||||
if p == nil {
|
||||
if len(p) == 0 {
|
||||
z.strm.next_in = (*C.Bytef)(unsafe.Pointer(nil))
|
||||
z.strm.avail_in = 0
|
||||
} else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче