[SERVER-18327] Coverity analysis defect 72086: Unchecked dynamic_cast Created: 05/May/15  Updated: 14/Apr/16  Resolved: 14/May/15

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Max Hirschhorn
Resolution: Duplicate Votes: 0
Labels: coverity
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-17858 Partial indexes should support more c... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Quint Iteration 3
Participants:

 Description   

Dynamic_cast may fail and return null if the type cast is incompatible

Defect 72086 (STATIC_C)
Checker FORWARD_NULL (subcategory dynamic_cast)
File: /src/mongo/db/matcher/expression_algo.cpp
Function mongo::expression::isClauseRedundant(const mongo::MatchExpression *, const mongo::MatchExpression *)
/src/mongo/db/matcher/expression_algo.cpp, line: 279
Dynamic cast to pointer "dynamic_cast <mongo::ExistsMatchExpression const *>(bar)" can return "NULL".

                    const ExistsMatchExpression* b = dynamic_cast<const ExistsMatchExpression*>(bar);

/src/mongo/db/matcher/expression_algo.cpp, line: 279
Assigning: "b" = "dynamic_cast <mongo::ExistsMatchExpression const *>(bar)".

                    const ExistsMatchExpression* b = dynamic_cast<const ExistsMatchExpression*>(bar);

/src/mongo/db/matcher/expression_algo.cpp, line: 281
Passing null pointer "b" to "path", which dereferences it. (The dereference happens because this is a virtual function call.)

                    return a->path() == b->path();



 Comments   
Comment by Max Hirschhorn [ 14/May/15 ]

Replaced dynamic_cast with static_cast as part of SERVER-18350.

Comment by Eric Milkie [ 05/May/15 ]

Either call dynamic_cast and check for null, or use static_cast. It's pointless to use dynamic_cast if you don't check for null.

Generated at Thu Feb 08 03:47:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.