Re: [HACKERS] Open 6.4 items

From: Tom Ivar Helbekkmo <tih(at)nhh(dot)no>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Paul A Vixie <vixie(at)vix(dot)com>, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Open 6.4 items
Date: 1998-10-10 18:14:51
Message-ID: 86k9285lno.fsf@athene.nhh.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> I think its behavior for an odd number of digits is wrong too, or at
> least pretty nonintuitive. I like my code a lot better ;-)

Well, I like your code better too on closer inspection. I changed it
a bit, though, because I don't feel that an odd number of digits in
the hex string is wrong at all -- it's just a representation of a bit
string, with the representation padded to an even multiple of four
bits.

Anyway, here's what I ended up with for the code in question:

if (ch == '0'&& (src[0] == 'x'|| src[0] == 'X')
&& isascii(src[1]) && isxdigit(src[1]))
{
/* Hexadecimal: Eat nybble string. */
if (size <= 0)
goto emsgsize;
tmp = 0;
dirty = 0;
src++; /* skip x or X. */
while ((ch = *src++) != '\0'&&
isascii(ch) && isxdigit(ch))
{
if (isupper(ch))
ch = tolower(ch);
n = strchr(xdigits, ch) - xdigits;
assert(n >= 0 && n <= 15);
tmp = (tmp << 4) | n;
if (++dirty == 2) {
if (size-- <= 0)
goto emsgsize;
*dst++ = (u_char) tmp;
tmp = 0, dirty = 0;
}
}
if (dirty) {
if (size-- <= 0)
goto emsgsize;
tmp <<= 4;
*dst++ = (u_char) tmp;
}
}

-tih
--
Popularity is the hallmark of mediocrity. --Niles Crane, "Frasier"

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Gene Selkov, Jr. 1998-10-10 20:06:16 a btree strategy hosed in 6.4.BETA1 and in current snapshot
Previous Message D'Arcy J.M. Cain 1998-10-10 16:32:13 Re: [HACKERS] Re: hackers-digest V1 #1013