Miscellaneous-NoUncheckedMalloc

The result of calls to the library functions “malloc”, “calloc”, and “realloc” must be checked

Required inputs: IR

Memory allocations can fail due to out-of-memory conditions. You should check for a NULL result immediately after calling a memory allocation function to avoid undefined behavior when running out of memory.
Example
S* ps = (S*)malloc(sizeof(S));
if (ps == NULL)
{
    return ERR_OUT_OF_MEMORY;
}

Possible Messages

Key

Text

Severity

Disabled

unchecked_malloc

Result of call to malloc, calloc, or realloc is not checked.

None

False

unchecked_new

Result of call to non-throwing operator new is not checked.

None

False

Options

check_nothrow_new

check_nothrow_new : bool = False

Whether the rule should also report unchecked usage of ::operator new(std::size_t, const std::nothrow_t &), which returns nullptr instead of throwing an exception of type std::bad_alloc if allocation fails.
 

null_check_macro

null_check_macro : bauhaus.analysis.config.MacroName = ''

Name of macro used to represent check for NULL.