diff options
author | Mathias Stearn <mathias@10gen.com> | 2018-04-09 16:28:14 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2018-04-18 15:20:34 -0400 |
commit | d976399cc97e4973cbd48191aa5730e8f01547a8 (patch) | |
tree | b3daf0d510c101ddc70472feeee925d0ef4c86a6 /src | |
parent | 2a1b247b29fdb037222d451d92568c79cbb341ae (diff) | |
download | mongo-d976399cc97e4973cbd48191aa5730e8f01547a8.tar.gz |
SERVER-34396 Fail to compile if io manipulators like std::hex are passed to StringBuilder/str::stream
This includes a partial revert of 80f409d1311eb8d20251d17be474aff382538b84
(SERVER-34307) to address this bug.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/bson/util/builder.h | 8 | ||||
-rw-r--r-- | src/mongo/db/storage/mmap_v1/dur.cpp | 22 | ||||
-rw-r--r-- | src/mongo/util/mongoutils/str.h | 8 |
3 files changed, 27 insertions, 11 deletions
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h index f82ffccc3fa..ccf4cd183fd 100644 --- a/src/mongo/bson/util/builder.h +++ b/src/mongo/bson/util/builder.h @@ -455,6 +455,14 @@ public: return optional ? *this << *optional : *this << "(None)"; } + /** + * Fail to compile if passed an unevaluated function, rather than allow it to decay and invoke + * the bool overload. This catches both passing std::hex (which isn't supported by this type) + * and forgetting to add () when doing `stream << someFuntion`. + */ + template <typename R, typename... Args> + StringBuilderImpl& operator<<(R (*val)(Args...)) = delete; + void appendDoubleNice(double x) { const int prev = _buf.l; const int maxSize = 32; diff --git a/src/mongo/db/storage/mmap_v1/dur.cpp b/src/mongo/db/storage/mmap_v1/dur.cpp index c8077f637d9..835f4302647 100644 --- a/src/mongo/db/storage/mmap_v1/dur.cpp +++ b/src/mongo/db/storage/mmap_v1/dur.cpp @@ -302,17 +302,17 @@ void debugValidateFileMapsMatch(const DurableMappedFile* mmf) { } } - invariant( - low == 0xffffffff, - str::stream() << "journal error warning views mismatch " << mmf->filename() << ' ' << hex - << low - << ".." - << high - << " len:" - << high - low + 1 - << ". priv loc: " - << (void*)(p + low) - << ". Written data does not match in-memory view. Missing WriteIntent?"); + if (low != 0xffffffff) { + std::stringstream ss; + ss << "journal error warning views mismatch " << mmf->filename() << ' ' << hex << low + << ".." << high << " len:" << high - low + 1; + + log() << ss.str() << endl; + log() << "priv loc: " << (void*)(p + low) << ' ' << endl; + + severe() << "Written data does not match in-memory view. Missing WriteIntent?"; + MONGO_UNREACHABLE; + } } diff --git a/src/mongo/util/mongoutils/str.h b/src/mongo/util/mongoutils/str.h index c7fbdd724ba..6891d3f3008 100644 --- a/src/mongo/util/mongoutils/str.h +++ b/src/mongo/util/mongoutils/str.h @@ -72,6 +72,14 @@ public: operator mongo::StringData() const { return ss.stringData(); } + + /** + * Fail to compile if passed an unevaluated function, rather than allow it to decay and invoke + * the bool overload. This catches both passing std::hex (which isn't supported by this type) + * and forgetting to add () when doing `stream << someFuntion`. + */ + template <typename R, typename... Args> + stream& operator<<(R (*val)(Args...)) = delete; }; inline bool startsWith(const char* str, const char* prefix) { |