I have used C for a few years but only recently made a serious effort to understand undefined behaviour and the pitfalls of C memory leaks etc. This is because now I use calloc several times in some code. The MISRA C recommendation is: Avoiding using functions and constructs that are prone to failure, for example, malloc may fail. I presume this means memory allocation could be a problem, does this mean calloc is secure? If not would this be advisable:
uint32_t *array;
array = calloc(length, 32);
or is it just window dressing?
Thank you for any advice, I really want to avoid bad practise.
Any call can fail. If there is no memory to allocate, malloc will return null. If you don't check this return value, and provide suitable handling logic for an out of memory event, your program may crash. Often the only thing you can do is provide a message to the user about the situation.
If you are in a safety critical enviroment, where a software crash could lead to a car crash, this is very bad, hence for any loop involving the real time operation of an automobile, dynamic memory allocation is best avoided, as would be potential recursion.
window dressing in the form of calloc is not going to make any difference.