Skip to content

Commit

Permalink
emu,ram: add assert() to catch out-of-bound memory accessing
Browse files Browse the repository at this point in the history
  • Loading branch information
sashimi-yzh committed Jul 26, 2020
1 parent a00e074 commit 39d61c8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/test/csrc/ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ void init_ram(const char *img) {

extern "C" void ram_helper(
uint64_t rIdx, uint64_t *rdata, uint64_t wIdx, uint64_t wdata, uint64_t wmask, uint8_t wen) {
assert(rIdx < RAMSIZE / sizeof(uint64_t));
*rdata = ram[rIdx];
if (wen) { ram[wIdx] = (ram[wIdx] & ~wmask) | (wdata & wmask); }
if (wen) {
assert(wIdx < RAMSIZE / sizeof(uint64_t));
ram[wIdx] = (ram[wIdx] & ~wmask) | (wdata & wmask);
}
}

0 comments on commit 39d61c8

Please sign in to comment.