• Guido Casati's avatar
    Fix misalignment issues in TLVEncoder macros ENCODE_U16, ENCODE_U24 · bac4f798
    Guido Casati authored
    This commit resolves undefined behaviour runtime errors related
    to misaligned memory access. E.g.
    
    > openair3/NAS/COMMON/IES/FGSMobileIdentity.c:193:3:
    > runtime error: store to misaligned address 0x608000021e2b for type 'uint16_t',
    > which requires 2 byte alignment 0x608000021e2b: note: pointer points here 00 f1 ...
    
    * ENCODE_U24: safely encode 24-bit values into a buffer
      by using memcpy to copy 3 bytes in network byte order (big-endian).
    * ENCODE_U16: safely encodes a 16-bit value into a buffer, handling
      misalignment by memcpy 2 bytes to buffer in network byte order (big-endian).
    bac4f798
TLVEncoder.h 4.85 KB