![]() |
![]() |
0696 | ![]() |
||||
![]() | |||||||
| Pointers | |||||||
A cast has been applied to the result of a call to malloc and the cast creates a pointer to a type which is larger than the amount of memory being allocated. This is almost certainly an error. For example:
/*PRQA S 1278,1307,1336,2017,2211,3198,3199,3203,3408,3602,3625,3631,3632,3672 ++*/
#include <stdlib.h>
#define SBUF 100U
typedef char TD[SBUF];
void foo(void)
{
TD * ptd;
ptd = (TD *) malloc(SBUF); /* OK */
ptd = (TD *) malloc(SBUF - 1U); /* Message 0696 */
}
No MISRA C:2012 Rules applicable to message 0696
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |