[SERVER-49772] Coverity analysis defect 115965: Copy without assign (RadixStore) Created: 21/Jul/20  Updated: 29/Oct/23  Resolved: 07/Jun/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Benety Goh
Resolution: Fixed Votes: 0
Labels: coverity, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-38037 Coverity analysis defect 105112: Copy... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Execution Team 2021-06-14
Participants:

 Description   

Copy without assign

This class has a user-defined copy constructor but no user-defined assignment operator. If the copy constructor is necessary to manage owned resources then a corresponding assignment operator is usually required. If an object of this type is assigned memory leaks and/or use-after-free errors may occur. Note that a compiler-generated assignment operator will perform only a bit-wise copy for any fields that do not have their own assignment operators defined. Class has user-written copy constructor but no user-written assignment operator
/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_radix_store.h:76: COPY_WITHOUT_ASSIGN 115965 Class "mongo::ephemeral_for_test::RadixStore<std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >" has a user-written copy constructor "mongo::ephemeral_for_test::RadixStore<std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::RadixStore(mongo::ephemeral_for_test::RadixStore<std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const &)" but no corresponding user-written assignment operator.
/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_radix_store.h:478: COPY_WITHOUT_ASSIGN 115965 User-written copy constructor.



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 07/Jun/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-49772 update RadixStore copy and move assignment operators
Branch: master
https://github.com/mongodb/mongo/commit/2d0aab0d859344a7bab7eddffd489206ada3afc5

Comment by Benety Goh [ 03/Jun/21 ]

We added an assignment operator in SERVER-38037. However, the declaration of the assignment operator must have confused Coverity because the assignment operator accepted a copy of a RadixStore rather than a const reference.

    friend void swap(RadixStore& first, RadixStore& second) {
        std::swap(first._root, second._root);
    }
 
...
    RadixStore& operator=(RadixStore other) {
        swap(*this, other);
        return *this;
    }

Comment by Henrik Edin [ 21/Jul/20 ]

We should add a copy assignment operator to the RadixStore class as there is a user defined copy constructor.

Generated at Thu Feb 08 05:20:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.