diff options
Diffstat (limited to 'src/mongo/db/ops/modifier_object_replace.cpp')
-rw-r--r-- | src/mongo/db/ops/modifier_object_replace.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/mongo/db/ops/modifier_object_replace.cpp b/src/mongo/db/ops/modifier_object_replace.cpp index 700f111e5b3..64bec6283d7 100644 --- a/src/mongo/db/ops/modifier_object_replace.cpp +++ b/src/mongo/db/ops/modifier_object_replace.cpp @@ -28,6 +28,7 @@ #include "mongo/db/ops/modifier_object_replace.h" +#include "mongo/base/data_view.h" #include "mongo/base/error_codes.h" #include "mongo/bson/mutable/document.h" #include "mongo/db/global_timestamp.h" @@ -48,13 +49,14 @@ Status fixupTimestamps(const BSONObj& obj) { // Skip _id field -- we do not replace it if (e.type() == bsonTimestamp && e.fieldNameStringData() != idFieldName) { - // TODO(emilkie): This is not endian-safe. - unsigned long long& timestamp = - *(reinterpret_cast<unsigned long long*>(const_cast<char*>(e.value()))); + auto timestampView = DataView(const_cast<char*>(e.value())); + + // We don't need to do an endian-safe read here, because 0 is 0 either way. + unsigned long long timestamp = timestampView.read<unsigned long long>(); if (timestamp == 0) { // performance note, this locks a mutex: Timestamp ts(getNextGlobalTimestamp()); - timestamp = ts.asULL(); + timestampView.write(tagLittleEndian(ts.asULL())); } } } |