Re: [HACKERS] inet data type regression test fails

Поиск
Список
Период
Сортировка
От Tatsuo Ishii
Тема Re: [HACKERS] inet data type regression test fails
Дата
Msg-id 199902240302.MAA25424@srapc451.sra.co.jp
обсуждение исходный текст
Ответ на Re: [HACKERS] inet data type regression test fails  ("Thomas G. Lockhart" <lockhart@alumni.caltech.edu>)
Ответы Re: [HACKERS] inet data type regression test fails  (Bruce Momjian <maillist@candle.pha.pa.us>)
Список pgsql-hackers
>> 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)         {
 


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

Предыдущее
От: "Daryl W. Dunbar"
Дата:
Сообщение: RE: [HACKERS] postmaster failure with 2-23 snapshot
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [GENERAL] Transaction logging