Skip to content

Commit

Permalink
Merge pull request #249 from jack15083/master
Browse files Browse the repository at this point in the history
fix not enough buf error when decode date
  • Loading branch information
AlexStocks authored Dec 22, 2020
2 parents c5a31e1 + d675604 commit 4014d7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions date.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (d *Decoder) decDate(flag int32) (time.Time, error) {
return ZeroDate, nil
case tag == BC_DATE: //'d': //date
s = buf[:8]
l, err = d.next(s)
l, err = d.nextFull(s)
if err != nil {
return t, err
}
Expand All @@ -93,7 +93,7 @@ func (d *Decoder) decDate(flag int32) (time.Time, error) {

case tag == BC_DATE_MINUTE:
s = buf[:4]
l, err = d.next(s)
l, err = d.nextFull(s)
if err != nil {
return t, err
}
Expand Down
5 changes: 5 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func (d *Decoder) next(b []byte) (int, error) {
return d.reader.Read(b)
}

// read byte arr, and return the real length of b
func (d *Decoder) nextFull(b []byte) (int, error) {
return io.ReadFull(d.reader, b)
}

// peek n bytes, will not advance the read ptr
func (d *Decoder) peek(n int) []byte {
b, _ := d.reader.Peek(n)
Expand Down

0 comments on commit 4014d7e

Please sign in to comment.