cancel
Showing results for 
Search instead for 
Did you mean: 

No error from null pointers

Carl_G
Senior

Hi,

I have been making a lot of calls into null pointers and am quite surprised at the results. I am expecting hard failures when I make this mistake but instead it seems that things just keep going and it takes a long time to realize I failed to initialize a pointer.

e.g.

LL_UCPD_RxEnable(Ports[PortNum].husbpd);

I have made this call which resolves to

#define SET_BIT(REG, BIT)     ((REG) |= (BIT))
__STATIC_INLINE void LL_UCPD_RxEnable(UCPD_TypeDef *UCPDx)
{
  SET_BIT(UCPDx->CR, UCPD_CR_PHYRXEN);
}

I have made this with the value husbpd uninitialized. But nothing negative happens other than the operation doesn't complete. No crash or other error.

Is there anything I can do or enable that will produce a harder fault when I make this mistake?

1 REPLY 1

There is memory mapped at ZERO, usually determined by the BOOTx pins

Perhaps enable asserts() so the library sanity checks the pointers/parameters passed into the HAL upper layers.

It will not help here, as it's not being checked.

You could fill uninitialized memory with 0xCDCDCDCD type pattern, or something similar, that's more likely to throw a fault when used.

Other Cortex-Mx parts you could perhaps play with watch points, or configure MPU to throw a MemManage_Handler

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..