From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1XDZTm-0005tn-9m for mharc-qemu-trivial@gnu.org; Sat, 02 Aug 2014 09:36:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDZTe-0005lE-QM for qemu-trivial@nongnu.org; Sat, 02 Aug 2014 09:36:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDZTY-0006KX-NA for qemu-trivial@nongnu.org; Sat, 02 Aug 2014 09:36:02 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:58810) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDZTM-0006Jn-4O; Sat, 02 Aug 2014 09:35:44 -0400 Received: from [192.168.88.2] (mjt.vpn.tls.msk.ru [192.168.177.99]) by isrv.corpit.ru (Postfix) with ESMTP id 6999240630; Sat, 2 Aug 2014 17:35:43 +0400 (MSK) Message-ID: <53DCE92F.3060507@msgid.tls.msk.ru> Date: Sat, 02 Aug 2014 17:35:43 +0400 From: Michael Tokarev Organization: Telecom Service, JSC User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.6.0 MIME-Version: 1.0 To: Chen Gang , Kevin Wolf , stefanha@redhat.com References: <53B90C35.6070501@gmail.com> In-Reply-To: <53B90C35.6070501@gmail.com> X-Enigmail-Version: 1.6 OpenPGP: id=804465C5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 86.62.121.231 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 X-BeenThere: qemu-trivial@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Aug 2014 13:36:09 -0000 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDZTS-0005ep-I7 for qemu-devel@nongnu.org; Sat, 02 Aug 2014 09:35:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDZTM-0006Jt-C2 for qemu-devel@nongnu.org; Sat, 02 Aug 2014 09:35:50 -0400 Message-ID: <53DCE92F.3060507@msgid.tls.msk.ru> Date: Sat, 02 Aug 2014 17:35:43 +0400 From: Michael Tokarev MIME-Version: 1.0 References: <53B90C35.6070501@gmail.com> In-Reply-To: <53B90C35.6070501@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-trivial] [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: Chen Gang , Kevin Wolf , stefanha@redhat.com Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org 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