Okay, so I'm newish to C, and I've been trying to learn by basically breaking stuff. I'm developing on a Proxmark3 Easy, and I wanted to see if I could replace the Memory manager it uses. I got it all to compile, but I'm running into an issue with some of the new code and I have no clue how to try and fix it. This is the repo in question: Attached is the local version of the code I'm working on. So, the issue: Calling `palloc_status()` crashes the Proxmark3. It correctly displays the MEM_USABLE and free memory, and outputs that the heap isn't null. It goes into the `count_blocks(pBlock* ptr)` function, and prints that the heap and ptr are not null. As soon as `ptr->next` is called, it crashes. What I gathered so far is there's possibly a problem with how the pointers are set up in `palloc_init()`. In the attached code, it gets to line 407 and it crashes there. I know the code on that line is weird, I've been throwing when I know at it to get it to work. All the structs are packed (since that was one of the issues I was having), and I'm on my wits end of trying to figure out _why_ it's not working when `ptr->next` is invoked.
I know nothing about embedded, but I'm going to take a guess by saying that the C compiler you are using to compile code for it (maybe it's just gcc/clang, idk) also supports these compilation flags. They have caught 95% of my errors the past 2 years programming C, so there's a good chance they can catch something for you too. If you want details on them, feel free to ask (or google). The fsanitize flags are able to even catch many runtime bugs: `-Wall -Wextra -Werror -Wpedantic -fsanitize=address,undefined -g`