문제

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 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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top