Уровень 0 · материалов: 2
В кластер входят документы, посвященные обязательной проверке возвращаемых значений функций выделения памяти, и не входят документы об общем управлении строками или использовании инструментов диагностики.
Общие признаки: функции выделения памяти, обработка NULL-указателей, неопределенное поведение, надежность кода на C
Группа выше: Управление памятью в C и C++
Смысл: The main idea is that checking the return value of memory allocation functions is mandatory for writing reliable and secure code, as ignoring NULL pointers leads to undefined behavior, silent memory corruption, and security vulnerabilities.
Developers must always check if memory allocation functions return NULL to avoid undefined behavior and silent memory corruption that OS protections cannot always prevent.
Смысл: The main idea is that using the `assert` macro to validate the result of memory allocation functions (like `malloc`) is a dangerous anti-pattern because asserts are typically disabled in production builds, leading to unchecked null pointer dereferences and undefined behavior in the final product.
Using `assert` to check `malloc` results is a mistake because `assert` is disabled in release builds, leaving production code vulnerable to null pointer crashes.