Ensure readVarInt handles short buf on first byte.
It is technically possible for the Read method on a reader to return zero bytes read with a nil error even though that behavior is "discouraged" by the interface documenation. This commit switches the read of the first byte to use io.ReadFull which will always error in this case.
This commit is contained in:
parent
5f971e10e6
commit
95ecbadb8e
1 changed files with 1 additions and 1 deletions
|
@ -53,7 +53,7 @@ func writeElements(w io.Writer, elements ...interface{}) error {
|
||||||
// readVarInt reads a variable length integer from r and returns it as a uint64.
|
// readVarInt reads a variable length integer from r and returns it as a uint64.
|
||||||
func readVarInt(r io.Reader, pver uint32) (uint64, error) {
|
func readVarInt(r io.Reader, pver uint32) (uint64, error) {
|
||||||
b := make([]byte, 1)
|
b := make([]byte, 1)
|
||||||
_, err := r.Read(b)
|
_, err := io.ReadFull(r, b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue