![]() |
![]() |
0317 | ![]() |
||||
![]() | |||||||
| Pointers | REFERENCE - ISO:C90-6.3.4 Cast Operators - Semantics | ||||||
An expression of type 'pointer-to-void' is being implicitly converted to a 'pointer-to-object' type. 'void pointers' should be used with care. A conversion of this kind can only be performed safely if the pointer is correctly aligned for the type of object being pointed to. Notice that the 'void pointers' returned by library functions
malloc, calloc and realloc are guaranteed to be suitably aligned so that they may address an object of any type. Message 0317 is not generated when the value returned by these functions is implicitly converted to a 'pointer-to-object' type.
For example:
/*PRQA S 702,1278,2017,2211,3120,3198,3199,3203,3227,3408,3602 ++*/
#include <stdlib.h>
extern void foo(unsigned char * puc)
{
void * pvd;
unsigned int * pui;
pui = (unsigned int *) puc; /* Messages 0310 and 3305 - dangerous */
pvd = (void *) puc; /* Message 0314 */
pvd = puc; /* Message 0315 */
pui = (unsigned int *) pvd; /* Message 0316 - dangerous */
pui = pvd; /* Message 0317 - dangerous */
pui = malloc(10u * sizeof(unsigned int)); /* */
pui = realloc(pui, 20u * sizeof(unsigned int)); /* Message 0315 */
free(pui); /* Message 0315 */
pui = calloc(10u, sizeof(unsigned int)); /* */
free(pui); /* Message 0315 */
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |