Menu

#27 Mashalling/unmarshalling does not work for 32 bit or higher data types on a 16 bit platform

1.2.0.0
closed
1188 (1)
2014-03-11
2014-03-07
No

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;
            }

Discussion

  • Armin-Hagen Weiss

    • labels: --> 1188
    • status: open --> closed
    • assigned_to: Armin-Hagen Weiss
     
  • Armin-Hagen Weiss

    All values >16 bits use explicit type cast for shift operations

     

Log in to post a comment.

MongoDB Logo MongoDB