Re: [HACKERS] inet data type regression test fails

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: t-ishii(at)sra(dot)co(dot)jp
Cc: lockhart(at)alumni(dot)caltech(dot)edu, 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:16:24
Message-ID: 199902240316.WAA04235@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Davis 1999-02-24 04:31:44 RE: [HACKERS] Transaction logging
Previous Message Tatsuo Ishii 1999-02-24 03:02:57 Re: [HACKERS] inet data type regression test fails