Skip to content

Commit

Permalink
fix staticcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fardream committed Dec 6, 2022
1 parent 90939a5 commit 1354b2b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions bcs/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func (d *Decoder) decodeVanilla(v reflect.Value) error {
return d.decodeStruct(v)

case reflect.Slice:
if v.Elem().Kind() == reflect.Uint8 {
return d.decodeByteSlice(v)
}

return d.decodeSlice(v)

case reflect.Array:
Expand All @@ -138,7 +142,7 @@ func (d *Decoder) decodeString(v reflect.Value) error {
return err
}

tmp := make([]byte, size, size)
tmp := make([]byte, size)

read, err := d.r.Read(tmp)
if err != nil {
Expand All @@ -155,7 +159,7 @@ func (d *Decoder) decodeString(v reflect.Value) error {
}

func (d *Decoder) readByte() (byte, error) {
b := make([]byte, 1, 1)
b := make([]byte, 1)
n, err := d.r.Read(b)
if err != nil {
return 0, err
Expand Down Expand Up @@ -228,7 +232,7 @@ func (d *Decoder) decodeByteSlice(v reflect.Value) error {
return err
}

tmp := make([]byte, size, size)
tmp := make([]byte, size)

read, err := d.r.Read(tmp)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion bcs/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (e *Encoder) encode(v reflect.Value) error {
return nil

default:
return fmt.Errorf("unsupported kind: %s, consider make the field ignored by using - tag or provide a customized Marshaler implementation.", kind.String())
return fmt.Errorf("unsupported kind: %s, consider make the field ignored by using - tag or provide a customized Marshaler implementation", kind.String())
}
}

Expand Down
2 changes: 1 addition & 1 deletion bcs/uleb128.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func ULEB128Encode[T ULEB128SupportedTypes](input T) []byte {
// - it accepts only [io.ByteReader], but the recommended way of creating one from [bufio.NewReader] will read more than 1 byte at the
// to fill the buffer.
func ULEB128Decode[T ULEB128SupportedTypes](r io.Reader) (T, int, error) {
buf := make([]byte, 1, 1)
buf := make([]byte, 1)
var v, shift T
var n int
for n < 10 {
Expand Down

0 comments on commit 1354b2b

Please sign in to comment.