From: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
---|---|
To: | Bruce Momjian <bruce(at)momjian(dot)us> |
Cc: | Joel Jacobson <joel(at)trustly(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: [BUG FIX] Compare returned value by socket() against PGINVALID_SOCKET instead of < 0 |
Date: | 2014-04-10 05:35:49 |
Message-ID: | CAA4eK1JtkJ-XR2DVzC70AiGGeDQpdb2+D5y9z+pN+LZhoc--Hg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, Apr 8, 2014 at 11:32 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> On Sun, Apr 6, 2014 at 11:45:59AM +0530, Amit Kapila wrote:
> In fact, this C program compiled by gcc on Debian issues no compiler
> warnings and returns 'hello', showing that -1 and ~0 compare as equal:
>
> int
> main(int argc, char **argv)
> {
> int i;
> unsigned int j;
>
> i = -1;
> j = ~0;
>
> if (i == j)
> printf("hello\n");
>
> return 0;
> }
I have add below code to check it's usage as per PG:
if (j < 0)
printf("hello-1\n");
It doesn't print hello-1, which means that all the check's in code
for <sock_desc> < 0 can have problem.
>> 1.
>> int
>> pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
>> sock = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
>> if (sock == SOCKET_ERROR)
>
> Well, the actual problem here is that WSASocket() returns INVALID_SOCKET
> per the documentation, not SOCKET_ERROR. I did not use PGINVALID_SOCKET
> here because this is Windows-specific code, defining 'sock' as SOCKET.
> We could have sock defined as pgsocket, but because this is Windows code
> already, it doesn't seem wise to mix portability code in there.
I think it's better to use check like below, just for matter of
consistency with other place
if (sock == INVALID_SOCKET)
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Pavan Deolasee | 2014-04-10 05:48:20 | Re: Autonomous Transaction (WIP) |
Previous Message | Rajeev rastogi | 2014-04-10 05:14:23 | Re: Autonomous Transaction (WIP) |