From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X3i30-000754-Qf for qemu-devel@nongnu.org; Sun, 06 Jul 2014 04:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X3i2r-0005M0-Ma for qemu-devel@nongnu.org; Sun, 06 Jul 2014 04:43:46 -0400 Message-ID: <53B90C35.6070501@gmail.com> Date: Sun, 06 Jul 2014 16:43:33 +0800 From: Chen Gang MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , stefanha@redhat.com, Michael Tokarev Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org 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. And make the related code match current qemu code styles, too. Signed-off-by: Chen Gang --- qemu-img.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index c98896b..8423e8e 100644 --- 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)) { buf[i++] = c; + } } buf[i] = '\0'; return 0; -- 1.7.11.7