Johnny Eriksson (bygg@sunet.se)
Mon, 16 Mar 1998 06:28:21 -0500
> Here's my weekend hacking project. Hope somebody finds it useful.
>
> Salvo Salasio
I do have a comment on a couple of your statements:
> switch (packet_tag & OLDLENGTH)
> {
> case 0:
> length = getbyte(pgpfile);
> break;
> case 1:
> length = getbyte(pgpfile) * 256 +
> getbyte(pgpfile);
> break;
> case 2:
> length = getbyte(pgpfile) * 256 * 256 * 256 +
> getbyte(pgpfile) * 256 * 256 +
> getbyte(pgpfile) * 256 +
> getbyte(pgpfile); /* Let compiler do it */
> break;
The code for cases 1 and 2 above depends on your compiler having the same
evaluation order as the byte order in the message. Reality is harsh, and
the eval order is unspecified in the ANSI C standard. I would suggest:
case 0:
length = getbyte(pgpfile);
break;
case 1:
length = getbyte(pgpfile) << 8;
length += getbyte(pgpfile);
break;
case 2:
length = getbyte(pgpfile) << 24;
length += getbyte(pgpfile) << 16;
length += getbyte(pgpfile) << 8;
length += getbyte(pgpfile);
break;
--Johnny
The following archive was created by hippie-mail 7.98617-22 on Fri Aug 21 1998 - 17:16:00 ADT