CS.UNINIT.LOCAL_VAR
Uninitialized local variable.
Vulnerability and risk
Using an appropriate value as the initial value when adding or modifying functions may cause unintended operation or inconsistency.
Mitigation and prevention
Local variables should be intentionally initialized at declaration time to clarify their use and possible values.
Example
Copy
namespace kmcustom
{
class C09
{
private int iUninitializedMember;//OK
void test()
{
//bool, byte, sbyte, char, decimal, double, float, int, uint, long, ulong, ushort, short
bool bInitialized = true;//OK
bool bUnitialized;//NG
bUnitialized = true;
byte byteUninitialized;
byteUninitialized = 1;
sbyte sbUninitalized;//NG
sbUninitalized = 1;
char cUninitalzied; //NG
cUninitalzied = 'a';
decimal decUninitalzied; //NG
decUninitalzied = 1;
double dbUninitalzied; //NG
dbUninitalzied = 0.1;
float fUninitalzied; //NG
fUninitalzied = 0.1F;
int iUninitalzied; //NG
iUninitalzied = 1;
uint uiUninitalzied; //NG
uiUninitalzied = 1;
long lUninitalzied; //NG
lUninitalzied = 1;
ulong ulUninitalzied; //NG
ulUninitalzied = 1;
ushort usUninitalzied; //NG
usUninitalzied = 1;
short sUninitalzied; //NG
sUninitalzied = 1;
}
}
}