From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkfFt-00072h-5Q for qemu-devel@nongnu.org; Thu, 06 Jun 2013 14:49:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkfFq-0008BV-Je for qemu-devel@nongnu.org; Thu, 06 Jun 2013 14:49:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkfFq-0008BD-9s for qemu-devel@nongnu.org; Thu, 06 Jun 2013 14:49:46 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r56InjUC000862 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Jun 2013 14:49:45 -0400 Message-ID: <51B0DA56.20504@redhat.com> Date: Thu, 06 Jun 2013 20:52:06 +0200 From: Laszlo Ersek MIME-Version: 1.0 References: <1370531573-17974-1-git-send-email-kraxel@redhat.com> In-Reply-To: <1370531573-17974-1-git-send-email-kraxel@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] fix Coverity scan SIGN_EXTENSION error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org, Markus Armbruster On 06/06/13 17:12, Gerd Hoffmann wrote: > Cc: Markus Armbruster > Signed-off-by: Gerd Hoffmann > --- > hw/display/qxl-render.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c > index f511a62..269b1a7 100644 > --- a/hw/display/qxl-render.c > +++ b/hw/display/qxl-render.c > @@ -199,7 +199,7 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor) > c->hot_y = cursor->header.hot_spot_y; > switch (cursor->header.type) { > case SPICE_CURSOR_TYPE_ALPHA: > - size = cursor->header.width * cursor->header.height * sizeof(uint32_t); > + size = sizeof(uint32_t) * cursor->header.width * cursor->header.height; > memcpy(c->data, cursor->chunk.data, size); > if (qxl->debug > 2) { > cursor_print_ascii_art(c, "qxl/alpha"); > Right. "width" and "height" are both "uint16_t" (short unsigned) and they are promoted to "int". The binding is then (int * int) * size_t int * size_t size_t * size_t size_t By the time the product would be converted to size_t ("unsigned" or "unsigned long" in practice, dependent on ILP32 or LP64), it may have overflowed (undefined behavior for signed int). The above changes it to (size_t * int) * int (size_t * size_t) * int size_t * int size_t * size_t size_t (BTW this is not order of evaluation, just how the types are determined by operator binding.) Reviewed-by: Laszlo Ersek