Skip to content

Commit

Permalink
memory: fix address range overlap with zero-sized resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-François Nguyen committed Jun 24, 2020
1 parent 4a6a948 commit 13a2370
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nmigen_soc/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _compute_addr_range(self, addr, size, step=1, *, alignment, extend):
if not isinstance(size, int) or size < 0:
raise ValueError("Size must be a non-negative integer, not {!r}"
.format(size))
size = self._align_up(size, alignment)
size = self._align_up(max(size, 1), alignment)

if addr > (1 << self.addr_width) or addr + size > (1 << self.addr_width):
if extend:
Expand Down
5 changes: 5 additions & 0 deletions nmigen_soc/test/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def test_add_resource_extend(self):
(0x10000, 0x10001))
self.assertEqual(memory_map.addr_width, 17)

def test_add_resource_size_zero(self):
memory_map = MemoryMap(addr_width=1, data_width=8)
self.assertEqual(memory_map.add_resource("a", size=0), (0, 1))
self.assertEqual(memory_map.add_resource("b", size=0), (1, 2))

def test_add_resource_wrong_address(self):
memory_map = MemoryMap(addr_width=16, data_width=8)
with self.assertRaisesRegex(ValueError,
Expand Down

0 comments on commit 13a2370

Please sign in to comment.