All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32
@ 2014-07-06  8:43 Chen Gang
  2014-08-02 13:35 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Gang @ 2014-07-06  8:43 UTC (permalink / raw)
  To: Kevin Wolf, stefanha, Michael Tokarev; +Cc: qemu-trivial, qemu-devel

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 <gang.chen.5i5j@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32
  2014-07-06  8:43 [Qemu-devel] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32 Chen Gang
@ 2014-08-02 13:35 ` Michael Tokarev
  2014-08-03  1:07   ` Chen Gang
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Tokarev @ 2014-08-02 13:35 UTC (permalink / raw)
  To: Chen Gang, Kevin Wolf, stefanha; +Cc: qemu-trivial, qemu-devel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32
  2014-08-02 13:35 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
@ 2014-08-03  1:07   ` Chen Gang
  0 siblings, 0 replies; 3+ messages in thread
From: Chen Gang @ 2014-08-03  1:07 UTC (permalink / raw)
  To: Michael Tokarev, Kevin Wolf, stefanha; +Cc: qemu-trivial, qemu-devel



On 08/02/2014 09:35 PM, Michael Tokarev wrote:
> 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:
> 

Thanks, and I shall continue to make another patches for qemu within
this month.

>> --- 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.
> 

OK, thanks.

>>              buf[i++] = c;
>> +        }
>>      }
>>      buf[i] = '\0';
>>      return 0;
> 
> Thanks,
> 
> /mjt
> 

Thanks.
-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-03  1:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-06  8:43 [Qemu-devel] [PATCH-trivial] qemu-img: Check getchar() return value in read_password() for WIN32 Chen Gang
2014-08-02 13:35 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-08-03  1:07   ` Chen Gang

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.