Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A [0:0] slice will return the entire contents, when it should return a empty object #52

@mr-eg9

Description

@mr-eg9

Consider the following.

ih = IntelHex({0:0, 1:1, 2:2})
# The bug
print(ih[0:0].tobinarray()) # array('B', [0, 1, 2])
# Correct for other indices
print(ih[1:1].tobinarray()) # array('B', [])

# stdlib __getitem__ for reference
li = [1, 2, 3]
print(li[0:0]) # []

Looking at the source for _getitem_() this behavior happens because the endaddr 0 evaluates the same as None.

The fix should simply be:

# Current
start = addr.start or addresses[0]
stop = addr.stop or (addresses[-1]+1)
# Fixed
start = addr.start if addr.start is not None else addresses[0]
stop = addr.stop if addr.stop is not None else (addresses[-1]+1)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions