Skip to content

Commit abbd53d

Browse files
committed
CSHARP-5135: Coverity analysis defect 127530: Dereference after null check.
1 parent d4e16ac commit abbd53d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,18 @@ public TNode VisitAndConvert<TNode>(TNode node)
8888
return null;
8989
}
9090

91-
var newNode = Visit(node) as TNode;
91+
var newNode = Visit(node);
92+
var convertedNewNode = newNode as TNode;
9293
if (newNode == null)
94+
{
95+
throw new InvalidOperationException($"Expected newNode to be a {typeof(TNode)}, not null.");
96+
}
97+
if (convertedNewNode == null)
9398
{
9499
throw new InvalidOperationException($"Expected newNode to be a {typeof(TNode)}, not a {newNode.GetType()}.");
95100
}
96101

97-
return newNode;
102+
return convertedNewNode;
98103
}
99104

100105
public IReadOnlyList<TNode> VisitAndConvert<TNode>(IReadOnlyList<TNode> nodes)

0 commit comments

Comments
 (0)