mirror of
https://github.com/pound-emu/ballistic.git
synced 2026-06-17 04:16:48 -07:00
35ef021fc9
The main focus of this commit is 'bal_safety.h'. This header file adds magic numbers to prevent Undefined Behavior. Right now this has only been added to 'bal_assembler_t'. This introduces 3 magic numbers: #define BAL_MAGIC_UNINITIALIZED 0x00000000U #define BAL_ASSEMBLER_MAGIC_ALIVE 0xBA11A550U #define BAL_ASSEMBLER_MAGIC_DEAD 0xDEADBA11U 'ALIVE' magic numbers will be set only if the struct has been initialized properly. Every function should check a struct's magic number to make sure it's not operating on a memory corrupted struct. 'DEAD' magic numbers should be set on a struct's 'destory()' function. This is done to prevent Double Free and Use-After-Free scenarios. Convenience macro 'BAL_CHECK_MAGIC' and 'BAL_CHECK_MAGIC_VOID' have been added to easily validate struct integrity. Signed-off-by: Ronald Caesar <github43132@proton.me>