FORWARD_NULL after derefencing null?
Asked Answered
S

1

7

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.

Senegal answered 28/3, 2012 at 14:9 Comment(1)
It would really help if you could give us some hints about the types involved...Todtoday
E
5

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();
Exactly answered 28/3, 2012 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.