1

We are checking code against cert rule and misra

I am getting: cert C issue PORTING.CAST.SIZE

void EDMADrv_setupChannel (uint8_t dmaChannel, const EDMADrv_TransferCfg* ptrTransferCfg)
{
    CSL_TpccRegs*      ptrEDMATPCCRegs;
    uint8_t                 tcc;
    uint16_t                paramId;
  paramId = (uint16_t)dmaChannel;//getting error from klocwork tool PORTING.CAST.SIZE ( Expression is cast to a type of potentially different size)

if assign

   uint16_t dmaChannelBit= dmaChannel;
   paramId = dmaChannelBit;

I get this error: STRONG.TYPE.ASSIGN.INIT (: A strongly typed value 'dmaChannel' of type 'uint8_t' is assigned to the variable 'dmaChannelBit' of a different strong type 'uint16_t')

can we ignore STRONG.TYPE.ASSIGN.INIT as we are assigning 8 bit to 16 bit . Or is there any other solution? can anyone tell if i ignore STRONG.TYPE.ASSIGN.INIT related issues .

flzzz
  • 553
  • 1
  • 4
  • 20
swethasree
  • 21
  • 3
  • Although tagged as `misra`, there is no MISRA violation reported here... `uint8_t` and `uint16_t` are the same *essential type category*, and the assignment is to a *wider* type: therefore Rule 10.3 is not violated. The cast is unnecessary, though. – Andrew Aug 25 '22 at 08:01
  • I agree it is not a misra errors how to solve PORTING.CAST.SIZE cert rule for paramId = (uint16_t)dmaChannel – swethasree Aug 25 '22 at 08:12
  • Well... `paramId = dmaChannel;` should be fine - standard integer promotion, which is well defined. If this is still a problem, you need to get in touch with Klockwork support. – Andrew Aug 25 '22 at 08:42
  • Thanks for reply ,I am same person who posted it . – swethasree Aug 25 '22 at 09:50

0 Answers0