r/Cprog • u/JarJarAwakens • Jun 18 '22
Why is 0 (null) considered to be a safe pointer?
/r/AskProgramming/comments/vfb7jh/why_is_0_null_considered_to_be_a_safe_pointer/
1
Upvotes
r/Cprog • u/JarJarAwakens • Jun 18 '22
3
u/crookedkr Jun 18 '22
Not everyone agrees that it's good practice to do that but the theory is that it will reduce use after free bugs/vulnerabilities.
1
u/flyingron Jan 24 '26
That doesn't necessarily make them safe. While passing a null pointer value to free() is required to do nothing, dereferencing null is still undefined behavior...
So, it can be a tool to write safe code, it doesn't guarantee safety.