Re: [HACKERS] inet data type regression test fails

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [HACKERS] inet data type regression test fails
Дата
Msg-id 199902240316.WAA04235@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: [HACKERS] inet data type regression test fails  (Tatsuo Ishii <t-ishii@sra.co.jp>)
Список pgsql-hackers
Applied.


> >> what is the correct result of
> >>   (0xffffffff >> ip_bits()) if ip_bits() == 32?
> >> > 1. 0x0
> >> > 2. 0xffffffff (actually does nothing)
> >
> >In both cases, it does something. I haven't looked it up, but I suspect
> >that this is an implementation-defined result, since you are seeing the
> >results of right-shifting the sign bit *or* the high bit downward. On
> >some systems it does not propagate, and on others it does.
> >
> >Have you tried coercing 0xffffffff to be a signed char? The better
> >solution is probably to mask the result before comparing, or handling
> >shifts greater than 31 as a special case. For example,
> >
> >  /* It's an IP V4 address: */
> >  int addr = htonl(ntohl(ip_v4addr(ip)) | (0xffffffff >> ip_bits(ip)));
> >
> >becomes
> >
> >  /* It's an IP V4 address: */
> >  int addr = htonl(ntohl(ip_v4addr(ip));
> >  if (ip_bits(ip) < sizeof(addr))
> >    addr |= (0xffffffff >> ip_bits(ip)));
> >
> >or something like that...
> 
> Thank you for the advice.  I concluded that current inet code has a
> portability problem. Included patches should be applied to both
> current and 6.4 tree. I have tested on LinuxPPC, FreeBSD and Solaris
> 2.6. Now the inet regression tests on these platforms are all happy.
> ---
> Tatsuo Ishii
> ------------------------------------------------------------------------
> *** pgsql/src/backend/utils/adt/network.c.orig    Fri Jan  1 13:17:13 1999
> --- pgsql/src/backend/utils/adt/network.c    Tue Feb 23 21:31:41 1999
> ***************
> *** 356,362 ****
>       if (ip_family(ip) == AF_INET)
>       {
>           /* It's an IP V4 address: */
> !         int    addr = htonl(ntohl(ip_v4addr(ip)) | (0xffffffff >> ip_bits(ip)));
>   
>           if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) == NULL)
>           {
> --- 356,367 ----
>       if (ip_family(ip) == AF_INET)
>       {
>           /* It's an IP V4 address: */
> !         int addr;
> !         unsigned long mask = 0xffffffff;
> ! 
> !         if (ip_bits(ip) < 32)
> !             mask >>= ip_bits(ip);
> !         addr = htonl(ntohl(ip_v4addr(ip)) | mask);
>   
>           if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) == NULL)
>           {
> 
> 


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [GENERAL] Transaction logging
Следующее
От: Michael Davis
Дата:
Сообщение: RE: [HACKERS] Transaction logging