C6001
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at C6001.
warning C6001: using uninitialized memory <variable>
This warning is reported when an uninitialized local variable is used before it is assigned a value. This could lead to unpredictable results. You should always initialize variables before use.
The following code generates this warning because variable i is only initialized if b is true; otherwise an uninitialized i is returned:
int f( bool b )
{
int i;
if ( b )
{
i = 0;
}
return i; // i is unintialized if b is false
}
To correct this warning, initialize the variable as shown in the following code:
int f( bool b )
{
int i= -1;
if ( b )
{
i = 0;
}
return i;
}
Show: