[previous] 0696 [next] The size of the allocated memory block is smaller than the size of the object type addressed by the pointer cast.
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 */
}

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents