Skip to main content
Senior II
February 22, 2025
Solved

Bad Pointer Checks

  • February 22, 2025
  • 1 reply
  • 386 views

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

This topic has been closed for replies.
Best answer by TDK

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.

1 reply

TDK
TDKBest answer
February 22, 2025

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""."