Received: from hesiod.nhh.no (hesiod.nhh.no [158.37.96.15]) by hub.org (8.8.8/8.8.8) with ESMTP id OAA27799 for ; Sat, 10 Oct 1998 14:15:02 -0400 (EDT) (envelope-from tih@athene.nhh.no) Received: from athene.nhh.no (athene.nhh.no [158.37.96.16]) by hesiod.nhh.no (8.8.8/8.8.8) with ESMTP id UAA02455; Sat, 10 Oct 1998 20:14:52 +0200 (CEST) Received: (from tih@localhost) by athene.nhh.no (8.8.8/8.8.8) id UAA00743; Sat, 10 Oct 1998 20:14:51 +0200 (CEST) Sender: tih@nhh.no To: Tom Lane Cc: Paul A Vixie , hackers@postgreSQL.org Subject: Re: [HACKERS] Open 6.4 items References: <23787.907968022@sss.pgh.pa.us> From: Tom Ivar Helbekkmo Date: 10 Oct 1998 20:14:51 +0200 In-Reply-To: Tom Lane's message of "Fri, 09 Oct 1998 17:20:22 -0400" Message-ID: <86k9285lno.fsf@athene.nhh.no> Lines: 48 X-Mailer: Gnus v5.6.27/Emacs 19.34 Tom Lane 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"