[previous] 0697 [next] The size of the allocated memory block is not an integral multiple of 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 this creates a pointer to an object type. However the amount of memory being allocated is not an integral multiple of the size of this object type. This is almost certainly an error.

For example:


/*PRQA S 1278,1307,1336,2017,2211,3120,3198,3199,3203,3408,3602,3625,3631,3632,3672 ++*/

#include <stdlib.h>

void foo(void)
{
    long * ptd;

    ptd = (long *) malloc(11);                     /* Message 0697 */
    ptd = (long *) malloc(12);                     /* OK           */
    ptd = (long *) malloc(13);                     /* Message 0697 */
}

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