For my company's project, I have ported the TRDP library to the Keil operating system for the C166 processor family. This is a 16 bit platform. Due to implicit casting, marshalling/unmarshalling will truncate 32 bit (or larger) data types. The following shows an example of the problem in the do_unmarshall() function. The code delimited by "#ifdef KEIL" illustrates my fix for the problem.
case TRDP_TIMEDATE32:
{
UINT32 *pDst32 = (UINT32 *) alignePtr(pDst, ALIGNOF(UINT32));
if (pDst + noOfItems * 4 > pInfo->pDstEnd)
{
return TRDP_PARAM_ERR;
}
while (noOfItems-- > 0)
{
#ifdef KEIL
*pDst32 = ((UINT32)(*pSrc++)) << 24;
*pDst32 += ((UINT32)(*pSrc++)) << 16;
*pDst32 += ((UINT32)(*pSrc++)) << 8;
#else
*pDst32 = *pSrc++ << 24;
*pDst32 += *pSrc++ << 16;
*pDst32 += *pSrc++ << 8;
#endif
*pDst32 += *pSrc++;
var_size = *pDst32;
pDst32++;
}
pDst = (UINT8 *) pDst32;
break;
}
All values >16 bits use explicit type cast for shift operations