diff options
author | yzshen <yzshen@chromium.org> | 2016-03-17 20:19:49 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-18 03:21:38 +0000 |
commit | ff43dcf4c622fb46b062abca1024a89fb01b54c7 (patch) | |
tree | fc710ceb7dd72d2805082cf33df48c056e86789d /mojo | |
parent | 86e5caf8d9d8490f645757bc886b942f10d0f7b1 (diff) | |
download | chromium_src-ff43dcf4c622fb46b062abca1024a89fb01b54c7.zip chromium_src-ff43dcf4c622fb46b062abca1024a89fb01b54c7.tar.gz chromium_src-ff43dcf4c622fb46b062abca1024a89fb01b54c7.tar.bz2 |
Mojo C++ bindings: fix sanity check of wtf string serialization.
Previously the code had a check that we use exactly the same WTF::String object
for GetSerializedSize_ and Serialize_ call. However, because WTF::String is
ref-counted, we may end up using different WTF::String objects referring to the
same contents. That may happen, e.g., when moving WTF::String to a different
container.
This CL changes the sanity check to verify that the size of WTF::String remains
unchanged.
BUG=595791
Review URL: https://codereview.chromium.org/1810253002
Cr-Commit-Position: refs/heads/master@{#381880}
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/public/cpp/bindings/lib/wtf_string_serialization.cc | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/mojo/public/cpp/bindings/lib/wtf_string_serialization.cc b/mojo/public/cpp/bindings/lib/wtf_string_serialization.cc index d1b749d..febd073 100644 --- a/mojo/public/cpp/bindings/lib/wtf_string_serialization.cc +++ b/mojo/public/cpp/bindings/lib/wtf_string_serialization.cc @@ -15,21 +15,20 @@ namespace WTF { namespace { -struct UTF8AdaptorWithPointer { - explicit UTF8AdaptorWithPointer(const WTF::String& input) - : utf8_adaptor(input) { +struct UTF8AdaptorInfo { + explicit UTF8AdaptorInfo(const WTF::String& input) : utf8_adaptor(input) { #if DCHECK_IS_ON() - original_input = reinterpret_cast<uintptr_t>(&input); + original_size_in_bytes = static_cast<size_t>(input.sizeInBytes()); #endif } - ~UTF8AdaptorWithPointer() {} + ~UTF8AdaptorInfo() {} WTF::StringUTF8Adaptor utf8_adaptor; #if DCHECK_IS_ON() - // For sanity check only. Never dereferenced. - uintptr_t original_input; + // For sanity check only. + size_t original_size_in_bytes; #endif }; @@ -38,7 +37,7 @@ class WTFStringContextImpl : public mojo::internal::WTFStringContext { WTFStringContextImpl() {} ~WTFStringContextImpl() override {} - std::queue<UTF8AdaptorWithPointer>& utf8_adaptors() { return utf8_adaptors_; } + std::queue<UTF8AdaptorInfo>& utf8_adaptors() { return utf8_adaptors_; } private: // When serializing an object, we call GetSerializedSize_() recursively on @@ -47,7 +46,7 @@ class WTFStringContextImpl : public mojo::internal::WTFStringContext { // serialization. If some WTF::Strings need to be converted to UTF8, we don't // want to do that twice. Therefore, we store a WTF::StringUTF8Adaptor for // each in the first pass, and reuse it in the second pass. - std::queue<UTF8AdaptorWithPointer> utf8_adaptors_; + std::queue<UTF8AdaptorInfo> utf8_adaptors_; DISALLOW_COPY_AND_ASSIGN(WTFStringContextImpl); }; @@ -87,8 +86,8 @@ void Serialize_(const WTF::String& input, DCHECK(!utf8_adaptors.empty()); #if DCHECK_IS_ON() - DCHECK_EQ(utf8_adaptors.front().original_input, - reinterpret_cast<uintptr_t>(&input)); + DCHECK_EQ(utf8_adaptors.front().original_size_in_bytes, + static_cast<size_t>(input.sizeInBytes())); #endif const WTF::StringUTF8Adaptor& adaptor = utf8_adaptors.front().utf8_adaptor; |