Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-hackers by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group