On 6 November 2018 at 12:38, li qiang <liq...@outlook.com> wrote: > > 在 2018/11/6 20:28, Paolo Bonzini 写道: >> On 06/11/2018 13:27, li qiang wrote: >>> The addr is 0~0x1fff, but when addr is at the near the end ,for example >>> 0x1fffe, the add>>2 can be 2047 >>> >>> and as script_ram is a uint32_t and so s->script_ram[addr >> 2] can read >>> out of the script_ram. >> How so? s->script_ram has size 2048, it's okay to access it at 2047. > > Oh, right. > > I'm confused by the script_ram, it's not byte array.
Incidentally, I think the read and write functions here would be somewhat clearer written as static void lsi_ram_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { LSIState *s = opaque; void *p = ((void *)s->script_ram) + addr; assert(addr + size <= sizeof(s->script_ram)); stn_p(p, size, val); } static uint64_t lsi_ram_read(void *opaque, hwaddr addr, unsigned size) { LSIState *s = opaque; void *p = ((void *)s->script_ram) + addr; assert(addr + size <= sizeof(s->script_ram)); return ldn_p(p, size); } thanks -- PMM