From 9d103b1de32216f94543699effc6ce82c4f8dcca Mon Sep 17 00:00:00 2001 From: Zihao Yu Date: Wed, 1 May 2019 18:03:29 +0800 Subject: [PATCH] am,nemu-devices,video: assertion fails when out of bound --- am/src/nemu-devices/nemu-video.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/am/src/nemu-devices/nemu-video.c b/am/src/nemu-devices/nemu-video.c index 555cb1fe..fc4becc3 100644 --- a/am/src/nemu-devices/nemu-video.c +++ b/am/src/nemu-devices/nemu-video.c @@ -24,13 +24,14 @@ size_t video_write(uintptr_t reg, void *buf, size_t size) { _DEV_VIDEO_FBCTL_t *ctl = (_DEV_VIDEO_FBCTL_t *)buf; int x = ctl->x, y = ctl->y, w = ctl->w, h = ctl->h; uint32_t *pixels = ctl->pixels; - int len = sizeof(uint32_t) * ( (x + w >= W) ? W - x : w ); + assert(x + w <= W && y + h <= H); + //int len = sizeof(uint32_t) * ( (x + w >= W) ? W - x : w ); + int len = sizeof(uint32_t) * w; uint32_t *p_fb = &fb[y * W + x]; int j; for (j = 0; j < h; j ++) { - if (y + j < H) { memcpy(p_fb, pixels, len); } - else { break; } + memcpy(p_fb, pixels, len); p_fb += W; pixels += w; }