On Thu, Apr 10, 2014 at 11:05:49AM +0530, Amit Kapila wrote:
> On Tue, Apr 8, 2014 at 11:32 PM, Bruce Momjian <bruce@momjian.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.
Ah, yes, good point. This is going to require backpatching then.
> >> 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)
Agreed. That is how I have coded the patch.
-- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB
http://enterprisedb.com
+ Everyone has their own god. +