Bad Byte Swap
Found this unfortunate routine in a code base:
uint32_t byteswap(uint32_t word) { uint8_t* ptr = (uint8_t*)&word; return ((ptr[3] << 24) | (ptr[2] << 16) | (ptr[1] << 8) | (ptr[0])); }
Too bad it only swaps in one direction. If you're already on a big-endian platform, this routine will do nothing! Probably not what you were expecting to happen. A correct routine will swap the byte order regardless of the platform it is running on:
http://www.yolinux.com/TUTORIALS/Endian-Byte-Order.html#SWAP













