[SERVER-20062] Coverity analysis defect 73597: Unsafe assignment operator Created: 20/Aug/15  Updated: 08/Jan/24  Resolved: 25/Sep/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: Andy Schwerin
Resolution: Done Votes: 0
Labels: coverity
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

Assignment operator does not check for self-assignment

Defect 73597 (STATIC_C)
Checker SELF_ASSIGN (subcategory none)
File: /src/mongo/s/catalog/forwarding_catalog_manager.cpp
Function mongo::ForwardingCatalogManager::ScopedDistLock::operator =(mongo::ForwardingCatalogManager::ScopedDistLock&&)
/src/mongo/s/catalog/forwarding_catalog_manager.cpp, line: 423
No protection against the object assigning to itself.

        _fcm = other._fcm;



 Comments   
Comment by Andy Schwerin [ 25/Sep/15 ]

acm and mira.carey@mongodb.com point out that automatically generated move operators don't make no-ops of self move, so this type of coverity warning if taken seriously equates to "write explicit move operators for everything."

Further, self move of an object that is not already in the moved-from state is a programming error that, while present in some standard algorithms from some providers, is avoidable by mortal programmers.

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