From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org
Cc: kwolf@redhat.com, qemu-block@nongnu.org
Subject: [Qemu-devel] [PATCH] qemu-io: Use getopt() correctly
Date: Tue, 12 May 2015 09:10:56 -0600 [thread overview]
Message-ID: <1431443456-21605-1-git-send-email-eblake@redhat.com> (raw)
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 <eblake@redhat.com>
---
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;
--
2.1.0
next reply other threads:[~2015-05-12 15:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-12 15:10 Eric Blake [this message]
2015-05-12 15:33 ` [Qemu-devel] [Qemu-block] [PATCH] qemu-io: Use getopt() correctly Alberto Garcia
2015-05-13 9:35 ` [Qemu-devel] " Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431443456-21605-1-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).