Why it is important to check what the malloc function returned
Unfortunately, many programmers are careless about checking of pointers, and sometimes they deliberately do not check whether to memory was allocated or not.
Why it is important to check what the malloc function returned
by Andrey Karpov
From the article:
There are 4 reasons at once, each of them is enough to prove that it is so necessary to write a check after you call the malloc function. If someone from your team doesn't write the checks, make him read this article.
- Null pointer dereference is undefined behavior
- Null pointer dereference is a vulnerability
- Where are guarantees that dereferencing of exactly a null pointer will occur?
- Where are the guarantees that memset fills the memory in a direct order?