cancel
Showing results for 
Search instead for 
Did you mean: 

Bad Pointer Checks

Carl_G
Senior

While working on a FLASH writing routing I got stumped with a bunch of flags being set in the SR register. It starts with CFGBSY. reading through the forums someone said they encountered this while accessing an uninitialized pointer. I found that I was doing the same. So my question is this, is there some type of exception or error that is being detected by this uninitialized access that I can see that would lead me faster to know I was using an uninitialized pointer?

 

Thanks

1 REPLY 1
TDK
Guru

As far as the chip is concerned, there is no difference between a regular access and an "uninitialized" access. If the pointer points to a valid memory space, it'll return what's there. If not, you'll get a hard fault. Note that 0x0 is a valid memory address.

If you don't want 0x0 to be a valid memory address, you can set the MPU to hard fault when it's accessed.

assert(ptr != null) type statements can be helpful. But there's no silver bullet for preventing uninitialized pointer bugs. Have to get the code right.

If you feel a post has answered your question, please click "Accept as Solution".