Question

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.

Was it helpful?

Solution

I suppose pathLookUpLocation is of type RegistryKey.

The reason for this message is that your code will throw a NullReferenceException if the value with the key specified by RegLookupKey is not found. This happens, because you pass null as the second parameter to GetValue. 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:

this.Path = pathLookUpLocation.GetValue(RegLookupKey, string.Empty).ToString();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top