Hi team,
I believe this is a bug: the function maxSizeOfDSMember() must not lower the maxSize in case of recursion, e.g., think of a sub-dataset with only CHAR8 members, would return overwriting with 1, even if the parent dataset has a previous UINT64 member with alignment 8.
I also believe a better name would have been maxAlignOfDSMember(), though this is typically the same, so never mind ;)
my fix so far:
static UINT8 maxAlignOfDSMember (TRDP_DATASET_T *pDataset) {
UINT8 maxAlign = 1;
UINT8 elemAlign;
if (pDataset != NULL) {
for (UINT16 lIndex = 0u; lIndex < pDataset->numElement; ++lIndex) {
elemAlign = (pDataset->pElement[lIndex].type <= TRDP_TIMEDATE64)
? cSizeOfBasicTypes[pDataset->pElement[lIndex].type]
: maxAlignOfDSMember(findDs(pDataset->pElement[lIndex].type));
if (maxAlign < elemAlign) maxAlign = elemAlign;
}
}
return maxAlign;
}
I have corrected the alignment in nested datasets and added correct structure padding to each dataset and replaced maxSizeOfDSMember with maxAlignOfDSMember, so that the alignment and padding would be based on alignment, not size of the largest member.