Skip to content

Commit

Permalink
Raise an exception on bad address range to the exclude function.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Sep 1, 2016
1 parent d8c9150 commit c8ec5ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 3 additions & 6 deletions bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from io import StringIO

__author__ = 'Erik Moqvist'
__version__ = '7.1.3'
__version__ = '7.1.4'

DEFAULT_WORD_SIZE_BITS = 8

Expand Down Expand Up @@ -733,9 +733,6 @@ def fill(self, value=b'\xff'):
"""

if self.segments.get_size() == 1:
return

previous_segment_maximum_address = None
fill_segments = []

Expand All @@ -761,8 +758,8 @@ def exclude(self, minimum_address, maximum_address):
"""

if maximum_address <= minimum_address:
return
if maximum_address < minimum_address:
raise Error('bad address range')

minimum_address *= self.word_size_bytes
maximum_address *= self.word_size_bytes
Expand Down
16 changes: 16 additions & 0 deletions tests/test_bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ def test_exclude_crop(self):
15 * b'\xff' +
b'3333')

# Exclude negative address range and expty address range.
binfile = bincopy.BinFile()
binfile.add_binary(b'111111')
with self.assertRaises(bincopy.Error) as cm:
binfile.exclude(4, 2)
self.assertEqual(str(cm.exception), 'bad address range')
binfile.exclude(2, 2)
self.assertEqual(binfile.as_binary(), b'111111')

def test_minimum_maximum(self):
binfile = bincopy.BinFile()

Expand Down Expand Up @@ -374,6 +383,13 @@ def test_overwrite(self):
binfile.add_binary(1024 * b'1', address=256, overwrite=True)
self.assertEqual(binfile.as_binary(minimum_address=256), 1024 * b'1')

def test_fill(self):
binfile = bincopy.BinFile()

# fill empty file
binfile.fill()
self.assertEqual(binfile.as_binary(), b'')

def test_performance(self):
binfile = bincopy.BinFile()

Expand Down

0 comments on commit c8ec5ee

Please sign in to comment.