pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Ivar Helbekkmo <tih@nhh.no>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Paul A Vixie <vixie@vix.com>
Cc: hackers@postgreSQL.org
Subject: Re: [HACKERS] Open 6.4 items
Date: 10 Oct 1998 20:14:51 +0200
Message-ID: <86k9285lno.fsf@athene.nhh.no> (raw)
References: <23787.907968022@sss.pgh.pa.us>

Tom Lane <tgl@sss.pgh.pa.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"



view thread (141+ messages)  latest in thread

Message-ID: <86k9285lno.fsf@athene.nhh.no>
Permalink:  ../86k9285lno.fsf@athene.nhh.no/
Also on:    postgresql.org/message-id/86k9285lno.fsf@athene.nhh.no

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tih@nhh.no, tgl@sss.pgh.pa.us, vixie@vix.com, hackers@postgreSQL.org
  Subject: Re: [HACKERS] Open 6.4 items
  In-Reply-To: <86k9285lno.fsf@athene.nhh.no>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox