diff mbox

[RFC,v1,3/4] util/oslib-win32: Fix up if conditional

Message ID 2c339ec0264c85f9c8a4884ffb8ebe059b3b9e4b.1498607452.git.alistair.francis@xilinx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alistair Francis June 27, 2017, 11:57 p.m. UTC
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Acked-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---

 util/oslib-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Fam Zheng June 29, 2017, 9:34 a.m. UTC | #1
On Tue, 06/27 16:57, Alistair Francis wrote:
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> Acked-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
> ---
> 
>  util/oslib-win32.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 7ec0f8e083..a015e1ac96 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -438,7 +438,7 @@ static int poll_rest(gboolean poll_msgs, HANDLE *handles, gint nhandles,
>          if (timeout == 0 && nhandles > 1) {
>              /* Remove the handle that fired */
>              int i;
> -            if (ready < nhandles - 1) {
> +            if ((ready - WAIT_OBJECT_0) < nhandles - 1) {
>                  for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) {
>                      handles[i-1] = handles[i];
>                  }
> -- 
> 2.11.0
> 

Reviewed-by: Fam Zheng <famz@redhat.com>
Paolo Bonzini June 29, 2017, 12:25 p.m. UTC | #2
On 28/06/2017 01:57, Alistair Francis wrote:
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> Acked-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
> ---
> 
>  util/oslib-win32.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 7ec0f8e083..a015e1ac96 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -438,7 +438,7 @@ static int poll_rest(gboolean poll_msgs, HANDLE *handles, gint nhandles,
>          if (timeout == 0 && nhandles > 1) {
>              /* Remove the handle that fired */
>              int i;
> -            if (ready < nhandles - 1) {
> +            if ((ready - WAIT_OBJECT_0) < nhandles - 1) {
>                  for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) {
>                      handles[i-1] = handles[i];
>                  }
> 

WAIT_OBJECT_0 is zero, but I agree it's better to add it.

However, the condition can be rewritten as ready - WAIT_OBJECT_0 + 1 <
nhandles, which is the same as the first iteration's "i < nhandles".  So
I'd just remove the "if" and "unindent" the for loop.

Paolo
Alistair Francis June 29, 2017, 4:31 p.m. UTC | #3
On Thu, Jun 29, 2017 at 5:25 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> On 28/06/2017 01:57, Alistair Francis wrote:
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> Acked-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
>> ---
>>
>>  util/oslib-win32.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
>> index 7ec0f8e083..a015e1ac96 100644
>> --- a/util/oslib-win32.c
>> +++ b/util/oslib-win32.c
>> @@ -438,7 +438,7 @@ static int poll_rest(gboolean poll_msgs, HANDLE *handles, gint nhandles,
>>          if (timeout == 0 && nhandles > 1) {
>>              /* Remove the handle that fired */
>>              int i;
>> -            if (ready < nhandles - 1) {
>> +            if ((ready - WAIT_OBJECT_0) < nhandles - 1) {
>>                  for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) {
>>                      handles[i-1] = handles[i];
>>                  }
>>
>
> WAIT_OBJECT_0 is zero, but I agree it's better to add it.
>
> However, the condition can be rewritten as ready - WAIT_OBJECT_0 + 1 <
> nhandles, which is the same as the first iteration's "i < nhandles".  So
> I'd just remove the "if" and "unindent" the for loop.

Ah, good spot. I'll remove it.

Thanks,
Alistair

>
> Paolo
diff mbox

Patch

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 7ec0f8e083..a015e1ac96 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -438,7 +438,7 @@  static int poll_rest(gboolean poll_msgs, HANDLE *handles, gint nhandles,
         if (timeout == 0 && nhandles > 1) {
             /* Remove the handle that fired */
             int i;
-            if (ready < nhandles - 1) {
+            if ((ready - WAIT_OBJECT_0) < nhandles - 1) {
                 for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) {
                     handles[i-1] = handles[i];
                 }