Search code examples
cstatic-analysisportability

Migrating from big to little endian: How to predetermine problematic code?


I am about to migrate a small project of C code (30+ kSLOC) from a 32-bit big to a 32-bit little endian platform. I would like to check ante festum, how much work this will be, so I would like to spot code that relies on the original endianess.

I am looking for an as comprehensive as possible collection of C code idioms, which are depending on big endian. Do not bother with the effort needed to detect the use of such idioms in real code, I have some code analysis tool support available.


Solution

  • Some things to look out for:

    • Fishy pointer casts and fishy type conversions between integer types of different sizes. These may also be latent alignment or strict aliasing bugs.
    • Serialization/de-serialization code, where data is read from/written to byte arrays.
    • Data communication interfaces without serialization/de-serialization code. That is: CPU just happened to have same endianess as the network, which is common for big endian systems in particular. Ethernet, CAN, UART and so on.
    • Structs with bit-fields.
    • Union type punning.