Potential fix for code scanning alert no. 25: Impossible interface nil check #374
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/NLstn/go-odata/security/code-scanning/25
In general, the problem is caused by wrapping a non-interface value (here, a
map[string]interface{}) into aninterface{}and then comparing that interface tonil. BecauseprocessMapEntityis declared to returnmap[string]interface{}, assigning its result directly to a variable of typeinterface{}ensures the resulting interface value is nevernil, makingif entityMap != nilalways true. To fix this, keep values in their concrete types as much as possible, and avoid unnecessary interface wrapping when your logic depends on distinguishing nil/non-nil.The best targeted fix here is to (1) change
addNavigationLinksso that it uses the same concrete type asprocessMapEntity—map[string]interface{}—for the processed entity, and (2) remove the impossible nil check. Specifically:entityMapinaddNavigationLinksfrominterface{}tomap[string]interface{}.processMapEntityalready match that type.processStructEntityOrderedcall, perform an explicit type assertion tomap[string]interface{}(which is what it presumably returns or is convertible to), and handle the “not ok” case by skipping the assignment.if entityMap != nilwrapper and instead unconditionally assign toresult[i]when the type assertion succeeds.These changes are confined to
internal/response/navigation_links.goand don’t require new imports or behavior changes; they only tighten the typing and make the control flow explicit.Suggested fixes powered by Copilot Autofix. Review carefully before merging.