![]() |
![]() |
2971 | ![]() |
||||
![]() | |||||||
| Unset data | |||||||
A pointer which addresses unset data is being passed as an argument to a function. However the function parameter is declared as pointer to a const qualified type and if it is dereferenced, the result will be undefined. If the function were going to use the pointer to write, it could well be appropriate to pass an argument which addresses uninitialised data. However, it can never be appropriate to pass such a pointer to a function if the corresponding parameter is declared as a pointer to a const qualified type, because no initialisation is possible. For example:
/*PRQA S 2017,3196,2983,2986,3199,3203,3204,3227,3348,3408,3447,3602 ++*/
extern int foo2(const int *p);
void foo1(void)
{
int y;
int r;
r = foo2(&y); /* 2971 */
}
MISRA-C:2004 Rules applicable to message 2971:
| Rule 9.1 (Required) | All automatic variables shall have been assigned a value before being used. |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |