Menu

#176 TRDP_LABEL_T breaks field alignment

1.4.0.0
closed
None
2018-05-02
2017-10-06
No

Reading the IEC 61375-2-3 spec, it is clear that the payload size of all teh packets is always a multiple of 4 bytes. Furthmore all the fields that exceed the 4-byte boundary in size are properly aligned and possibly

If I understand correctly, structs marked with GNU_PACKED can be sent as payload of TRDP packets.

When a field of a GNU_PACKED struct is of the type TRDP_LABEL_T, the correct alignment is lost. This because TRDP_LABEL_T is 17 bytes long since it is defined like this (in trdp_types.h and iec-61375-2-3.h):

#define TRDP_MAX_LABEL_LEN                  16u
typedef CHAR8 TRDP_LABEL_T[TRDP_MAX_LABEL_LEN + 1]

I propose to define another type, i.e. TRDP_PACKED_LABEL_T to be used in the GNU_PACKED structs:

typedef CHAR8 TRDP_PACKED_LABEL_T[TRDP_MAX_LABEL_LEN]

This together with a pair of functions to copy data from TRDP_LABEL_T to TRDP_PACKED_LABEL_T and vice-versa without overflow.

Please evaluate the attached patch.

1 Attachments

Discussion

  • Lorenzo Buzzi

    Lorenzo Buzzi - 2017-10-06

    Sorry, I don't know why I cannot edit my post. The correct and complete version of the initial sentences is:

    Reading the IEC 61375-2-3 spec, it is clear that the payload size of all the packets is always a multiple of 4 bytes. Furthmore all the fields that exceed the 4-byte boundary in size are properly aligned and possibly padded.

     
  • Bernd Löhr

    Bernd Löhr - 2017-11-13
    • status: open --> accepted
    • assigned_to: Bernd Löhr
     
  • Bernd Löhr

    Bernd Löhr - 2017-11-13

    Yes, you're right - the packets defined in the utility functions will be corrected.

     
  • Bernd Löhr

    Bernd Löhr - 2017-11-13
    • status: accepted --> pending
     
  • Bernd Löhr

    Bernd Löhr - 2018-05-02
    • status: pending --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB