diff options
author | Bernard Gorman <bernard.gorman@gmail.com> | 2020-10-27 20:01:45 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-28 00:35:45 +0000 |
commit | b5fafa1f87dda6f8773c5a8a1a5e7776d4d94da7 (patch) | |
tree | 83b69156aa8cd1061e06f784e7c2339dcdc3f9d2 | |
parent | 16186d9f4a5f7dd83af728d3d5c3660420181b38 (diff) | |
download | mongo-b5fafa1f87dda6f8773c5a8a1a5e7776d4d94da7.tar.gz |
SERVER-51853 Always initialize the numInserted out-parameter in AbstractIndexAccessMethod::insertKeysr4.4.2-rc0
(cherry picked from commit 8177334703d89a19f38246c5ca95cbf3e5470d91)
-rw-r--r-- | src/mongo/db/index/index_access_method.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/index/index_access_method.h | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index f88d721ae16..b37c38e713c 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -183,6 +183,10 @@ Status AbstractIndexAccessMethod::insertKeys(OperationContext* opCtx, const InsertDeleteOptions& options, KeyHandlerFn&& onDuplicateKey, int64_t* numInserted) { + // Initialize the 'numInserted' out-parameter to zero in case the caller did not already do so. + if (numInserted) { + *numInserted = 0; + } // Add all new keys into the index. The RecordId for each is already encoded in the KeyString. for (const auto& keyString : keys) { bool unique = _descriptor->unique(); diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h index 63be0cf3186..3a58f512159 100644 --- a/src/mongo/db/index/index_access_method.h +++ b/src/mongo/db/index/index_access_method.h @@ -109,7 +109,9 @@ public: /** * Inserts the specified keys into the index. Does not attempt to determine whether the - * insertion of these keys should cause the index to become multikey. + * insertion of these keys should cause the index to become multikey. The 'numInserted' output + * parameter, if non-nullptr, will be reset to the number of keys inserted by this function + * call, or to zero in the case of either a non-OK return Status or an empty 'keys' argument. */ virtual Status insertKeys(OperationContext* opCtx, const KeyStringSet& keys, |