Skip to content

Commit

Permalink
feat: handle nil cases
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvladco committed Feb 4, 2025
1 parent adb9b24 commit 1a4cdc2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/serialization/codec/jam/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ func (br *byteReader) decodeBitsFixedLength(v *BitSequence, bytesLength uint) (e
if _, err = br.Reader.Read(bb); err != nil {
return err
}
if bytesLength == 0 {
return nil
}
*v = make(BitSequence, bytesLength*8)
for i := range *v {
mod := i % 8
Expand Down
2 changes: 1 addition & 1 deletion pkg/serialization/codec/jam/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (bw *byteWriter) encodeBytes(b []byte) error {

func (bw *byteWriter) encodeBits(bitSequence BitSequence) error {
length := len(bitSequence) / 8
if length%8 == 0 {
if length > 0 && length%8 == 0 {
length += 1
}
err := bw.encodeLength(length)
Expand Down

0 comments on commit 1a4cdc2

Please sign in to comment.