From: Jia Liu Date: Wed, 21 Aug 2013 01:31:36 +0000 (+0800) Subject: hw/openrisc: Avoid undefined shift in openrisc_pic_cpu_handler() X-Git-Tag: v2.7.1~2336^2 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=7717f248eebdcfe6de400404d0cf65dcb3633308;p=mirror_qemu.git hw/openrisc: Avoid undefined shift in openrisc_pic_cpu_handler() In C99 signed shift (1 << 31) is undefined behavior, since the result exceeds INT_MAX. Use 1U instead and move the shift after the check. Signed-off-by: Xi Wang Acked-by: Jia Liu --- diff --git a/hw/openrisc/pic_cpu.c b/hw/openrisc/pic_cpu.c index 3fcee02619..2af1d6013a 100644 --- a/hw/openrisc/pic_cpu.c +++ b/hw/openrisc/pic_cpu.c @@ -26,12 +26,14 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) { OpenRISCCPU *cpu = (OpenRISCCPU *)opaque; CPUState *cs = CPU(cpu); - uint32_t irq_bit = 1 << irq; + uint32_t irq_bit; if (irq > 31 || irq < 0) { return; } + irq_bit = 1U << irq; + if (level) { cpu->env.picsr |= irq_bit; } else {