I have this line of code:
this.Path = pathLookUpLocation.GetValue(RegLookupKey, null).ToString();
When I run static analysis tool (Coverity) on my code I get a FORWARD_NULL here, saying that I am dereferencing null here. I am having trouble understanding what that means and how I would go about fixing it?
this.Path is a string, pathLookUpLocation is a RegistryKey, RegLookupKey is a string.
I suppose
pathLookUpLocationis of typeRegistryKey.The reason for this message is that your code will throw a
NullReferenceExceptionif the value with the key specified byRegLookupKeyis not found. This happens, because you passnullas the second parameter toGetValue. The second parameter is the default value that is returned if the key can’t be found.Fix it by changing it to
string.Empty: