From patchwork Tue May 12 15:10:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 471383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 165A8140D16 for ; Wed, 13 May 2015 01:11:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=comcast.net header.i=@comcast.net header.b=ZAUrZ+sT; dkim-atps=neutral Received: from localhost ([::1]:43537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsBqF-0000Ji-50 for incoming@patchwork.ozlabs.org; Tue, 12 May 2015 11:11:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsBpu-0008PQ-IA for qemu-devel@nongnu.org; Tue, 12 May 2015 11:11:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YsBpq-0005qA-FB for qemu-devel@nongnu.org; Tue, 12 May 2015 11:11:10 -0400 Received: from resqmta-po-02v.sys.comcast.net ([96.114.154.161]:41092) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsBpq-0005pw-9D for qemu-devel@nongnu.org; Tue, 12 May 2015 11:11:06 -0400 Received: from resomta-po-07v.sys.comcast.net ([96.114.154.231]) by resqmta-po-02v.sys.comcast.net with comcast id T3Az1q0034zp9eg013B4wU; Tue, 12 May 2015 15:11:04 +0000 Received: from red.redhat.com ([24.10.254.122]) by resomta-po-07v.sys.comcast.net with comcast id T3Ax1q0052fD5rL013B2uK; Tue, 12 May 2015 15:11:03 +0000 From: Eric Blake To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Date: Tue, 12 May 2015 09:10:56 -0600 Message-Id: <1431443456-21605-1-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1431443464; bh=0HaQeHrBihCpzepcKDXh1zxtBjFO8LyeDTZva82sI/U=; h=Received:Received:From:To:Subject:Date:Message-Id; b=ZAUrZ+sTeCePXkywq1Sdz3RcHe0cdCr6F4+l+2sNuLF0hAVkSK6yVEfXfQ7Q31Ma0 kkJs9iIb0EI6F+3r6PSFoZmb0jKLNGqQF2FIpUXyix5kg5LS7qauNjIfppgu4bE2r7 UdgQgTLoCoORJlYAHEKQ9p8w9CA5JcP+Tx9AZPQ+x97rwjAF91N9IWsbLEd3S+261n Q266GMj3C2206Y7UPo0hBHMLCmaZoavGvn5J7gEwmrKcSxF1W7u9Le3RaWykc+cUwa JbKUESacF2pSRinmIPKuFbww3MI0IijlwkvQyVy9pYe9twuVykTpefsELATvZ3JB6A Z66rpUdIFVziA== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 96.114.154.161 Cc: kwolf@redhat.com, qemu-block@nongnu.org Subject: [Qemu-devel] [PATCH] qemu-io: Use getopt() correctly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org POSIX says getopt() returns -1 on completion. While Linux happens to define EOF as -1, this definition is not required by POSIX, and there may be platforms where checking for EOF instead of -1 would lead to an infinite loop. Signed-off-by: Eric Blake Reviewed-by: Alberto Garcia --- qemu-io-cmds.c | 16 ++++++++-------- qemu-io.c | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 1afcfc0..52dc611 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -646,7 +646,7 @@ static int read_f(BlockBackend *blk, int argc, char **argv) int total = 0; int pattern = 0, pattern_offset = 0, pattern_count = 0; - while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) { + while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != -1) { switch (c) { case 'b': bflag = 1; @@ -830,7 +830,7 @@ static int readv_f(BlockBackend *blk, int argc, char **argv) int pattern = 0; int Pflag = 0; - while ((c = getopt(argc, argv, "CP:qv")) != EOF) { + while ((c = getopt(argc, argv, "CP:qv")) != -1) { switch (c) { case 'C': Cflag = 1; @@ -961,7 +961,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv) int total = 0; int pattern = 0xcd; - while ((c = getopt(argc, argv, "bcCpP:qz")) != EOF) { + while ((c = getopt(argc, argv, "bcCpP:qz")) != -1) { switch (c) { case 'b': bflag = 1; @@ -1116,7 +1116,7 @@ static int writev_f(BlockBackend *blk, int argc, char **argv) int pattern = 0xcd; QEMUIOVector qiov; - while ((c = getopt(argc, argv, "CqP:")) != EOF) { + while ((c = getopt(argc, argv, "CqP:")) != -1) { switch (c) { case 'C': Cflag = 1; @@ -1228,7 +1228,7 @@ static int multiwrite_f(BlockBackend *blk, int argc, char **argv) int i; BlockRequest *reqs; - while ((c = getopt(argc, argv, "CqP:")) != EOF) { + while ((c = getopt(argc, argv, "CqP:")) != -1) { switch (c) { case 'C': Cflag = 1; @@ -1463,7 +1463,7 @@ static int aio_read_f(BlockBackend *blk, int argc, char **argv) struct aio_ctx *ctx = g_new0(struct aio_ctx, 1); ctx->blk = blk; - while ((c = getopt(argc, argv, "CP:qv")) != EOF) { + while ((c = getopt(argc, argv, "CP:qv")) != -1) { switch (c) { case 'C': ctx->Cflag = 1; @@ -1562,7 +1562,7 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv) struct aio_ctx *ctx = g_new0(struct aio_ctx, 1); ctx->blk = blk; - while ((c = getopt(argc, argv, "CqP:")) != EOF) { + while ((c = getopt(argc, argv, "CqP:")) != -1) { switch (c) { case 'C': ctx->Cflag = 1; @@ -1779,7 +1779,7 @@ static int discard_f(BlockBackend *blk, int argc, char **argv) int64_t offset; int count; - while ((c = getopt(argc, argv, "Cq")) != EOF) { + while ((c = getopt(argc, argv, "Cq")) != -1) { switch (c) { case 'C': Cflag = 1; diff --git a/qemu-io.c b/qemu-io.c index 8e41080..ae5e274 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -120,7 +120,7 @@ static int open_f(BlockBackend *blk, int argc, char **argv) QemuOpts *qopts; QDict *opts; - while ((c = getopt(argc, argv, "snrgo:")) != EOF) { + while ((c = getopt(argc, argv, "snrgo:")) != -1) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT;