[SERVER-68787] Coverity analysis defect 122591: AUTO_CAUSES_COPY Created: 12/Aug/22  Updated: 27/Oct/23  Resolved: 26/Aug/22

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Coverity Collector User Assignee: Kevin Cherkauer
Resolution: Works as Designed Votes: 0
Labels: coverity, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2022-08-12 at 9.51.41 AM.png    
Sprint: QE 2022-09-05
Participants:

 Description   

AUTO_CAUSES_COPY

Unnecessary object copies can affect performance. Using the auto keyword without an & causes a copy.
/src/mongo/db/pipeline/accumulator_multi.cpp:426: AUTO_CAUSES_COPY 122591 Using the "auto" keyword without an "&" causes the copy of an object of type SortPatternPart.



 Comments   
Comment by Kevin Cherkauer [ 26/Aug/22 ]

The source of the range loop returns const iterators, so a copy is made to the loop variable as the loop changes the state of the copy, which it is not allowed to do to the original because of constness.

Comment by Githook User [ 26/Aug/22 ]

Author:

{'name': 'Kevin Cherkauer', 'email': 'kevin.cherkauer@mongodb.com', 'username': 'kevin-cherkauer'}

Message: SERVER-68787 Note why for loop is making a copy in comment
Branch: master
https://github.com/mongodb/mongo/commit/9b5ae4a246aa43c49a8d099a4f81be64cd6e100c

Comment by Mickey Winters [ 12/Aug/22 ]

I think we want a copy here since _sortPattern is a local variable. later in the serialize method we serialize with the original queries sort pattern. NOT the modified sort pattern we construct here. I could have expressed this better with const auto and explicitly making a copy

Comment by Kyle Suarez [ 12/Aug/22 ]

CC mickey.winters@mongodb.com

Generated at Thu Feb 08 06:11:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.