Re: [HACKERS] inet data type regression test fails

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
Cc: pgsql-patches(at)postgreSQL(dot)org, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] inet data type regression test fails
Date: 1999-02-24 03:02:57
Message-ID: 199902240302.MAA25424@srapc451.sra.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)
{

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-02-24 03:16:24 Re: [HACKERS] inet data type regression test fails
Previous Message Bruce Momjian 1999-02-24 03:02:07 Re: [GENERAL] Transaction logging