![]() |
![]() |
2972 | ![]() |
||||
![]() | |||||||
| Unset data | |||||||
A pointer which may sometimes address 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. It may be appropriate to pass a pointer to some uninitialised data as an argument to a function that will then initialise the data. However, it can never be appropriate to pass such a pointer to a function if the corresponding parameter is declared as pointer to a const qualified type, because no initialisation is possible. For example:
/*PRQA S 2017,3196,2983,2986,3199,3203,3204,3227,3349,3408,3447,3602 ++*/
extern int foo2(const int *p);
void foo1(int a)
{
int x;
int r;
if (a == 1)
{
x = 1;
}
r = foo2(&x); /* 2972 */
}
MISRA C:2012 Rules applicable to message 2972:
| Rule-9.1 (Mandatory) | The value of an object with automatic storage duration shall not be read before it has been set |
See also:
![]() | ||
| 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 |