Out-of-bounds access (ARRAY_VS_SINGLETON) error

0

I am getting an error while solving this embedded systems problem that includes bitwise operation. I have three questions regarding this problem:

1) For the union class eFuseWord83_t I do not get what : means when it is declaring its elements uint32_t LFOSC_CAL : LFOSC_CAL_BITSIZE;

2) The error before status = SYS_eFuse_SECDED_CheckAndCorrect(&sfrAtopOscCtrlReg, LFOSC_CAL_BITSIZE, (uint32_t) word83Data.bits.LFOSC_SECDED ); states that Out-of-bounds access (ARRAY_VS_SINGLETON) 9. callee_ptr_arith: Passing &sfrAtopOscCtrlReg to function SYS_eFuse_SECDED_CheckAndCorrect which uses it as an array. This might corrupt or misinterpret adjacent memory locations.

3) This function triggers some other functions that you do not need to worry about as there is no error over there; But then uint32_t XorArray32(uint32_t* pData, uint32_t DataBitSize) gets called out where we have the error on xor_result ^= Xor32(pData[i++] & (left_bits < 32 ? (1 << left_bits) - 1 : 0xFFFFFFFF)); which states ptr_arith: Performing pointer arithmetic on pData in expression pData + I++ and so this is where the Out of bounds error is happening. Please do note that pData = &sfrAtopOscCtrlReg and DataBitSize = LFO_C_BITSIZE.

#define LFO_C_BITSIZE 7
#define SFR_AON_ATOP_LFO_C_LFO_C_MASK       (0x000001FFUL << 0)

union eFuseWord83_t
{
    struct
    {
       uint32_t CRC16_PROD : 16;
       uint32_t LFO_C : LFO_C_BITSIZE;   
       uint32_t LFOSC_SECDED : 5;  
       uint32_t reserved : 4;
    } bits;
    uint32_t all32;
};

sfrAtopOscCtrlReg = (uint32_t) SFR_AON_ATOP_LFO_C_LFO_C_MASK & (uint32_t) word83Data.bits.LFOSC_CAL;

status = SYS_eFuse_SECDED_CheckAndCorrect(&sfrAtopOscCtrlReg, LFO_C_BITSIZE, (uint32_t) word83Data.bits.LFOSC_SECDED );

 uint32_t XorArray32(uint32_t* pData, uint32_t DataBitSize)
{
   uint32_t xor_result = 0;
   uint32_t      i = 0;
   int32_t left_bits;

   for (left_bits = (int32_t)DataBitSize; left_bits > 0; left_bits -= 32)
   {
      xor_result ^= Xor32(pData[i++] & (left_bits < 32 ? (1 << left_bits) - 1 : 0xFFFFFFFF));
   }

   return xor_result;
}

INLINE uint32_t Xor32(uint32_t Data)
{
   uint32_t xor_result;

   // Perform XOR operation in 5 stages (log2(32)) - each time Xor half of the bits together.
   xor_result = (Data & 0xFFFF) ^ (Data >> 16);
   xor_result = (xor_result & 0xFF) ^ (xor_result >> 8);
   xor_result = (xor_result & 0xF) ^ (xor_result >> 4);
   xor_result = (xor_result & 0x3) ^ (xor_result >> 2);
   xor_result = (xor_result & 0x1) ^ (xor_result >> 1);

   // Return results
   return xor_result;
}

c++
c
pointers
embedded
indexoutofboundsexception
asked on Stack Overflow Jun 12, 2020 by Ashish101

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0