mirror of https://gitlab.com/qemu-project/qemu
vt82c686: fix coverity warning about out-of-bounds write
Refactor superio_ioport_writeb to fix the out of bounds write warning. In addition, fix two typos: s/chage/change/ Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
parent
7766aa0c0e
commit
b196d969ef
|
@ -50,13 +50,13 @@ typedef struct VT82C686BState {
|
||||||
static void superio_ioport_writeb(void *opaque, hwaddr addr, uint64_t data,
|
static void superio_ioport_writeb(void *opaque, hwaddr addr, uint64_t data,
|
||||||
unsigned size)
|
unsigned size)
|
||||||
{
|
{
|
||||||
int can_write;
|
|
||||||
SuperIOConfig *superio_conf = opaque;
|
SuperIOConfig *superio_conf = opaque;
|
||||||
|
|
||||||
DPRINTF("superio_ioport_writeb address 0x%x val 0x%x\n", addr, data);
|
DPRINTF("superio_ioport_writeb address 0x%x val 0x%x\n", addr, data);
|
||||||
if (addr == 0x3f0) {
|
if (addr == 0x3f0) {
|
||||||
superio_conf->index = data & 0xff;
|
superio_conf->index = data & 0xff;
|
||||||
} else {
|
} else {
|
||||||
|
bool can_write = true;
|
||||||
/* 0x3f1 */
|
/* 0x3f1 */
|
||||||
switch (superio_conf->index) {
|
switch (superio_conf->index) {
|
||||||
case 0x00 ... 0xdf:
|
case 0x00 ... 0xdf:
|
||||||
|
@ -68,31 +68,28 @@ static void superio_ioport_writeb(void *opaque, hwaddr addr, uint64_t data,
|
||||||
case 0xf7:
|
case 0xf7:
|
||||||
case 0xf9 ... 0xfb:
|
case 0xf9 ... 0xfb:
|
||||||
case 0xfd ... 0xff:
|
case 0xfd ... 0xff:
|
||||||
can_write = 0;
|
can_write = false;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
can_write = 1;
|
|
||||||
|
|
||||||
if (can_write) {
|
|
||||||
switch (superio_conf->index) {
|
|
||||||
case 0xe7:
|
case 0xe7:
|
||||||
if ((data & 0xff) != 0xfe) {
|
if ((data & 0xff) != 0xfe) {
|
||||||
DPRINTF("chage uart 1 base. unsupported yet\n");
|
DPRINTF("change uart 1 base. unsupported yet\n");
|
||||||
|
can_write = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0xe8:
|
case 0xe8:
|
||||||
if ((data & 0xff) != 0xbe) {
|
if ((data & 0xff) != 0xbe) {
|
||||||
DPRINTF("chage uart 2 base. unsupported yet\n");
|
DPRINTF("change uart 2 base. unsupported yet\n");
|
||||||
|
can_write = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (can_write) {
|
||||||
superio_conf->config[superio_conf->index] = data & 0xff;
|
superio_conf->config[superio_conf->index] = data & 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
superio_conf->config[superio_conf->index] = data & 0xff;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t superio_ioport_readb(void *opaque, hwaddr addr, unsigned size)
|
static uint64_t superio_ioport_readb(void *opaque, hwaddr addr, unsigned size)
|
||||||
|
|
Loading…
Reference in New Issue