Skip to content

Commit

Permalink
[bugfix] concatenate zero-length buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinlampin committed Jan 14, 2025
1 parent 7981e3e commit 3018fc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions microschc/binary/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def __add__(self, other: 'Buffer') -> 'Buffer':
left:Buffer = self
right:Buffer = other

if right.length == 0:
new_buffer: Buffer = left.copy()
return new_buffer

# Calculate new length
new_length: int = left.length + right.length

Expand Down
5 changes: 5 additions & 0 deletions tests/binary/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ def test_add():
left_right: Buffer = left + right
expected: Buffer = Buffer(content=b'\x00\x8a\xf9\x10', length=29, padding=Padding.RIGHT)
assert left_right == expected

left: Buffer = Buffer(content=b'\x00\x8a\xf8', length=23, padding=Padding.RIGHT)
right: Buffer = Buffer(content=b'', length=0)
left_right: Buffer = left + right
assert left_right == left

def test_or():
# 0x08 0x68
Expand Down

0 comments on commit 3018fc1

Please sign in to comment.