tcp: Explicitly do a pointer comparison for converting to a boolean integer

Message ID 1378715396-81785-1-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Sept. 9, 2013, 8:29 a.m.
This fixes warnings in some compiler versions, and avoids the
theoretical case where the lower 32 bits of the pointer would all
be zero where the implicit cast wouldn't give the right result.
---
 libavformat/tcp.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Luca Barbato Sept. 9, 2013, 8:43 a.m. | #1
On 09/09/13 10:29, Martin Storsjö wrote:
> This fixes warnings in some compiler versions, and avoids the
> theoretical case where the lower 32 bits of the pointer would all
> be zero where the implicit cast wouldn't give the right result.
> ---
>  libavformat/tcp.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index 39065aa..837d0fd 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -100,7 +100,8 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>          }
>      } else {
>          if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
> -                                     timeout * 100, h, cur_ai->ai_next)) < 0) {
> +                                     timeout * 100, h,
> +                                     cur_ai->ai_next ? 1 : 0)) < 0) {
>  
>              if (ret == AVERROR_EXIT)
>                  goto fail1;
> 

ok
Luca Barbato Sept. 9, 2013, 8:44 a.m. | #2
On 09/09/13 10:29, Martin Storsjö wrote:
> This fixes warnings in some compiler versions, and avoids the
> theoretical case where the lower 32 bits of the pointer would all
> be zero where the implicit cast wouldn't give the right result.
> ---
>  libavformat/tcp.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index 39065aa..837d0fd 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -100,7 +100,8 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>          }
>      } else {
>          if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
> -                                     timeout * 100, h, cur_ai->ai_next)) < 0) {
> +                                     timeout * 100, h,
> +                                     cur_ai->ai_next ? 1 : 0)) < 0) {
>  

Better using !! maybe.

lu
Martin Storsjö Sept. 9, 2013, 12:06 p.m. | #3
On Mon, 9 Sep 2013, Luca Barbato wrote:

> On 09/09/13 10:29, Martin Storsjö wrote:
>> This fixes warnings in some compiler versions, and avoids the
>> theoretical case where the lower 32 bits of the pointer would all
>> be zero where the implicit cast wouldn't give the right result.
>> ---
>>  libavformat/tcp.c |    3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
>> index 39065aa..837d0fd 100644
>> --- a/libavformat/tcp.c
>> +++ b/libavformat/tcp.c
>> @@ -100,7 +100,8 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>>          }
>>      } else {
>>          if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
>> -                                     timeout * 100, h, cur_ai->ai_next)) < 0) {
>> +                                     timeout * 100, h,
>> +                                     cur_ai->ai_next ? 1 : 0)) < 0) {
>> 
>
> Better using !! maybe.

What do others prefer, this or the other style?

// Martin

Patch

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 39065aa..837d0fd 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -100,7 +100,8 @@  static int tcp_open(URLContext *h, const char *uri, int flags)
         }
     } else {
         if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
-                                     timeout * 100, h, cur_ai->ai_next)) < 0) {
+                                     timeout * 100, h,
+                                     cur_ai->ai_next ? 1 : 0)) < 0) {
 
             if (ret == AVERROR_EXIT)
                 goto fail1;