From: Michael Tokarev <mjt@tls.msk.ru>
To: Chen Gang <gang.chen.5i5j@gmail.com>,
Kevin Wolf <kwolf@redhat.com>,
stefanha@redhat.com
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32
Date: Sat, 02 Aug 2014 17:35:43 +0400 [thread overview]
Message-ID: <53DCE92F.3060507@msgid.tls.msk.ru> (raw)
In-Reply-To: <53B90C35.6070501@gmail.com>
06.07.2014 12:43, Chen Gang wrote:
> getchar() is a standard c library function which may return with failure
> (e.g. -1), so like another platforms, also need check it under WIN32.
Applied to -trivial queue, with a slight modification:
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -185,15 +185,21 @@ static int GCC_FMT_ATTR(2, 3) qprintf(bool quiet, const char *fmt, ...)
> static int read_password(char *buf, int buf_size)
> {
> int c, i;
> +
> printf("Password: ");
> fflush(stdout);
> i = 0;
> for(;;) {
> c = getchar();
> - if (c == '\n')
> + if (c < 0) {
> + buf[i] = '\0';
> + return -1;
> + } else if (c == '\n') {
> break;
> - if (i < (buf_size - 1))
> + }
> + if (i < (buf_size - 1)) {
I've added an 'else' there and merged with the previous line,
to match with the above code which is being added.
> buf[i++] = c;
> + }
> }
> buf[i] = '\0';
> return 0;
Thanks,
/mjt
WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: Chen Gang <gang.chen.5i5j@gmail.com>,
Kevin Wolf <kwolf@redhat.com>,
stefanha@redhat.com
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32
Date: Sat, 02 Aug 2014 17:35:43 +0400 [thread overview]
Message-ID: <53DCE92F.3060507@msgid.tls.msk.ru> (raw)
In-Reply-To: <53B90C35.6070501@gmail.com>
06.07.2014 12:43, Chen Gang wrote:
> getchar() is a standard c library function which may return with failure
> (e.g. -1), so like another platforms, also need check it under WIN32.
Applied to -trivial queue, with a slight modification:
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -185,15 +185,21 @@ static int GCC_FMT_ATTR(2, 3) qprintf(bool quiet, const char *fmt, ...)
> static int read_password(char *buf, int buf_size)
> {
> int c, i;
> +
> printf("Password: ");
> fflush(stdout);
> i = 0;
> for(;;) {
> c = getchar();
> - if (c == '\n')
> + if (c < 0) {
> + buf[i] = '\0';
> + return -1;
> + } else if (c == '\n') {
> break;
> - if (i < (buf_size - 1))
> + }
> + if (i < (buf_size - 1)) {
I've added an 'else' there and merged with the previous line,
to match with the above code which is being added.
> buf[i++] = c;
> + }
> }
> buf[i] = '\0';
> return 0;
Thanks,
/mjt
next prev parent reply other threads:[~2014-08-02 13:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-06 8:43 [Qemu-trivial] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32 Chen Gang
2014-07-06 8:43 ` [Qemu-devel] " Chen Gang
2014-08-02 13:35 ` Michael Tokarev [this message]
2014-08-02 13:35 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-08-03 1:07 ` Chen Gang
2014-08-03 1:07 ` [Qemu-devel] " Chen Gang
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=53DCE92F.3060507@msgid.tls.msk.ru \
--to=mjt@tls.msk.ru \
--cc=gang.chen.5i5j@gmail.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=stefanha@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.