Skip to content

Commit

Permalink
Correctly write over the page boundary in SetUnaligned
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Jan 7, 2025
1 parent 8ff9318 commit 0546f18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rvgo/fast/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (m *Memory) SetUnaligned(addr uint64, dat []byte) {
m.Invalidate(addr) // invalidate this branch of memory, now that the value changed
}

copy(p.Data[pageAddr:], dat)
copy(p.Data[pageAddr:], dat[d:])
}

func (m *Memory) GetUnaligned(addr uint64, dest []byte) {
Expand Down
9 changes: 9 additions & 0 deletions rvgo/fast/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,12 @@ func TestMemoryBinary(t *testing.T) {
m.GetUnaligned(8, dest[:])
require.Equal(t, uint8(123), dest[0])
}

func TestMemoryInvalidSetUnaligned(t *testing.T) {
t.Run("SetUnaligned incorrectly writes to next page", func(t *testing.T) {
m := NewMemory()
m.SetUnaligned(0x0FFE, []byte{0xaa, 0xbb, 0xcc, 0xdd})
require.Equal(t, m.pages[0].Data[4094:], []byte{0xaa, 0xbb})
require.Equal(t, m.pages[1].Data[0:2], []byte{0xcc, 0xdd})
})
}

0 comments on commit 0546f18

Please sign in to comment.