[AGENT++] Bug in asn1.cpp on 64-bit architecture
Jochen Katz
katz at agentpp.com
Fri Feb 6 21:29:01 CET 2009
Hi,
> It is related to the fact that on 64-bit architecture (both Solaris
> and Linux) sizeof(int)==4 but sizeof(long)==8, while on 32-bit
> architecture both types are 4 bytes long.
>
> ! *length >>= (8 * ((sizeof(unsigned long)) - lengthbyte));
> ! *length >>= (8 * ((sizeof(int)) - lengthbyte));
I thought that this was fixed before. But as under my 64 bit linux it
has to be the sizeof(int) (because ntohl() works on 32 bit values!), I
suggest the following:
- memcpy((char *)length, (char *)data + 1, (int)lengthbyte);
- *length = ntohl(*length);
- *length >>= (8 * ((sizeof(int)) - lengthbyte));
+ for (int i=0 ; i < lengthbyte ; i++)
+ {
+ *length = (*length << 8) + *(data + 1 + i);
+ }
This eliminates both, the sizeof() and the ntohl(). (Please report if
this does not work on yor system).
Regards,
Jochen
More information about the AGENTPP
mailing list