From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2r74-0004ly-B3 for qemu-devel@nongnu.org; Fri, 26 Jul 2013 19:07:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2r73-0003TC-Et for qemu-devel@nongnu.org; Fri, 26 Jul 2013 19:07:54 -0400 Received: from mail-ee0-x22d.google.com ([2a00:1450:4013:c00::22d]:61524) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2r73-0003T1-4z for qemu-devel@nongnu.org; Fri, 26 Jul 2013 19:07:53 -0400 Received: by mail-ee0-f45.google.com with SMTP id c50so29816eek.32 for ; Fri, 26 Jul 2013 16:07:52 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <51F30134.7070300@redhat.com> Date: Sat, 27 Jul 2013 01:07:32 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1358870255-32335-1-git-send-email-xi.wang@gmail.com> In-Reply-To: <1358870255-32335-1-git-send-email-xi.wang@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] target-or32: fix masking in openrisc_pic_cpu_handler() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xi Wang Cc: Blue Swirl , qemu-devel@nongnu.org, Jia Liu Il 22/01/2013 16:57, Xi Wang ha scritto: > A correct mask should be `x & (1 << i)', rather than `x && (1 << i)'. > > Also, in C99 signed shift (1 << 31) is undefined behavior, since the > result exceeds INT_MAX; use 1U instead. > > Signed-off-by: Xi Wang > --- > hw/openrisc_pic.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/hw/openrisc_pic.c b/hw/openrisc_pic.c > index aaeb9a9..4f6d5a0 100644 > --- a/hw/openrisc_pic.c > +++ b/hw/openrisc_pic.c > @@ -26,12 +26,14 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) > { > OpenRISCCPU *cpu = (OpenRISCCPU *)opaque; > int i; > - 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 { > @@ -39,11 +41,11 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) > } > > for (i = 0; i < 32; i++) { > - if ((cpu->env.picsr && (1 << i)) && (cpu->env.picmr && (1 << i))) { > + if ((cpu->env.picsr & (1U << i)) && (cpu->env.picmr & (1U << i))) { > cpu_interrupt(&cpu->env, CPU_INTERRUPT_HARD); > } else { > cpu_reset_interrupt(&cpu->env, CPU_INTERRUPT_HARD); > - cpu->env.picsr &= ~(1 << i); > + cpu->env.picsr &= ~(1U << i); > } > } > } > Ping. Paolo