From patchwork Wed May 1 17:01:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bruce Rogers X-Patchwork-Id: 10925411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABF1C92A for ; Wed, 1 May 2019 17:02:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9418828D4F for ; Wed, 1 May 2019 17:02:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8779828F34; Wed, 1 May 2019 17:02:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 28D2028D4F for ; Wed, 1 May 2019 17:02:51 +0000 (UTC) Received: from localhost ([127.0.0.1]:37086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLsd8-0003FZ-I0 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 May 2019 13:02:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLscB-0002qI-8V for qemu-devel@nongnu.org; Wed, 01 May 2019 13:01:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLsc6-0006IF-Gx for qemu-devel@nongnu.org; Wed, 01 May 2019 13:01:50 -0400 Received: from inet-orm.provo.novell.com ([137.65.248.124]:47010 helo=mail.novell.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hLsc6-000609-3c for qemu-devel@nongnu.org; Wed, 01 May 2019 13:01:46 -0400 Received: from brogers1.provo.novell.com ([137.65.184.169]) by mail.novell.com with ESMTP (NOT encrypted); Wed, 01 May 2019 11:01:30 -0600 From: Bruce Rogers To: qemu-devel@nongnu.org Date: Wed, 1 May 2019 11:01:25 -0600 Message-Id: <20190501170125.10244-1-brogers@suse.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.248.124 Subject: [Qemu-devel] [PATCH] scsi-disk: assert positive value to avoid compiler warning X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, pbonzini@redhat.com, jsnow@redhat.com, Bruce Rogers Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP While investigating link-time-optimization, the compiler complained as follows: In function ‘scsi_disk_new_request_dump’, inlined from ‘scsi_new_request.part.24’ at hw/scsi/scsi-disk.c:2549:9, inlined from ‘scsi_new_request’ at hw/scsi/scsi-disk.c:2533:21: hw/scsi/scsi-disk.c:2523:19: error: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=] hw/scsi/scsi-disk.c: In function ‘scsi_new_request’: /usr/include/glib-2.0/glib/gmem.h:78:10: note: in a call to allocation function ‘g_malloc’ declared here gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); Asserting that len is positive avoids this diagnostic. This assert is reasonable since the error case of scsi_cdb_length() has already been handled by a previous call to that function. Signed-off-by: Bruce Rogers Reviewed-by: John Snow --- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index e7e865ab3b..ac180fdddf 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2520,6 +2520,7 @@ static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf) int len = scsi_cdb_length(buf); char *line_buffer, *p; + assert(len > 0); line_buffer = g_malloc(len * 5 + 1); for (i = 0, p = line_buffer; i < len; i++) {