[SERVER-51385] Ensure that vector is initialized before setting vector as output of std::transform Created: 06/Oct/20  Updated: 29/Oct/23  Resolved: 07/Oct/20

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Bug Priority: Major - P3
Reporter: Blake Oler Assignee: Blake Oler
Resolution: Fixed Votes: 0
Labels: PM-234-M1, PM-234-T-lifecycle
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-51209 Fill in missing gaps in Resharding wo... Closed
is depended on by SERVER-51210 Call setInitialChunksAndZones from th... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Sharding 2020-10-19
Participants:

 Description   

There are a few valid ways to output to a newly declared vector from std::transform. For example:

  1. Initialize the vector to the size of the input, so that std::transform can properly index into each memory space, OR
  2. Use std::back_inserter, which is an iterator that will call push_back on the output vector for each input element.

If one attempts to use std::transform on an uninitialized vector without using std::back_inserter, std::transform will induce a segfault attempting to index into memory that hasn't yet been allocated.

This ticket is to fix an instance of that bug in Resharding code.



 Comments   
Comment by Githook User [ 07/Oct/20 ]

Author:

{'name': 'Blake Oler', 'email': 'blake.oler@mongodb.com', 'username': 'BlakeIsBlake'}

Message: SERVER-51385 Initialize vector with size before using as output of std::transform
Branch: master
https://github.com/mongodb/mongo/commit/bcbebf4314d929e2708a58620e8d00c3de9958b5

Comment by Blake Oler [ 06/Oct/20 ]

CC haley.connelly. I had no idea this was a thing until today!

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