From 7cba2e17d08fb7d4ccc88ea4ff02a068bad5091f Mon Sep 17 00:00:00 2001 From: Melvin He Date: Tue, 7 May 2024 00:08:06 -0400 Subject: [PATCH] Fix: bmqp messageproperties Wconv warns (#273) Signed-off-by: Melvin He Signed-off-by: Patrick M. Niedzielski --- .../bmq/bmqp/bmqp_messageproperties.cpp | 26 +++++++++----- src/groups/bmq/bmqp/bmqp_messageproperties.h | 3 +- .../bmq/bmqp/bmqp_messageproperties.t.cpp | 35 ++++++++++++------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/groups/bmq/bmqp/bmqp_messageproperties.cpp b/src/groups/bmq/bmqp/bmqp_messageproperties.cpp index 6eae621e4..2346440b6 100644 --- a/src/groups/bmq/bmqp/bmqp_messageproperties.cpp +++ b/src/groups/bmq/bmqp/bmqp_messageproperties.cpp @@ -105,12 +105,16 @@ class PropertyValueStreamOutVisitor { void operator()(const bsl::string& value) { - bdlbb::BlobUtil::append(d_blob_p, value.c_str(), value.length()); + bdlbb::BlobUtil::append(d_blob_p, + value.c_str(), + static_cast(value.length())); } void operator()(const bsl::vector& value) { - bdlbb::BlobUtil::append(d_blob_p, value.data(), value.size()); + bdlbb::BlobUtil::append(d_blob_p, + value.data(), + static_cast(value.size())); } }; @@ -450,8 +454,8 @@ bool MessageProperties::remove(const bsl::string& name, // Decrement 'd_totalSize' by property name's length and length of struct // 'MessagePropertyHeader'. - d_totalSize -= it->first.length(); - d_totalSize -= sizeof(MessagePropertyHeader); + d_totalSize -= static_cast(it->first.length()); + d_totalSize -= static_cast(sizeof(MessagePropertyHeader)); if (p.d_offset) { // Cannot remove the property since reading other properties needs @@ -942,7 +946,8 @@ MessageProperties::streamOut(bdlbb::BlobBufferFactory* bufferFactory, true); // write flag new (msgPropHeader.object()) MessagePropertyHeader(); msgPropHeader->setPropertyType(p.d_type); - msgPropHeader->setPropertyNameLength(cit->first.length()); + msgPropHeader->setPropertyNameLength( + static_cast(cit->first.length())); if (info.isExtended()) { msgPropHeader->setPropertyValueLength(offset); } @@ -952,7 +957,7 @@ MessageProperties::streamOut(bdlbb::BlobBufferFactory* bufferFactory, msgPropHeader.reset(); // write out the header totalSize += sizeof(MessagePropertyHeader); - offset += cit->first.length(); + offset += static_cast(cit->first.length()); offset += p.d_length; } @@ -970,8 +975,10 @@ MessageProperties::streamOut(bdlbb::BlobBufferFactory* bufferFactory, } // Append property name. - bdlbb::BlobUtil::append(blob, cit->first.c_str(), cit->first.length()); - totalSize += cit->first.length(); + bdlbb::BlobUtil::append(blob, + cit->first.c_str(), + static_cast(cit->first.length())); + totalSize += static_cast(cit->first.length()); // Append property value. @@ -1064,7 +1071,8 @@ bsl::ostream& MessageProperties::print(bsl::ostream& stream, bdlma::LocalSequentialAllocator lsa(0); mwcu::MemOutStream os(k_MAX_BYTES_DUMP, &lsa); - os << bdlb::PrintStringHexDumper(&binaryVec[0], printSize); + os << bdlb::PrintStringHexDumper(&binaryVec[0], + static_cast(printSize)); printer.printAttribute(nameOs.str().data(), os.str()); } break; diff --git a/src/groups/bmq/bmqp/bmqp_messageproperties.h b/src/groups/bmq/bmqp/bmqp_messageproperties.h index 9f88a1078..917999e8a 100644 --- a/src/groups/bmq/bmqp/bmqp_messageproperties.h +++ b/src/groups/bmq/bmqp/bmqp_messageproperties.h @@ -654,7 +654,8 @@ MessageProperties::setProperty(const bsl::string& name, const TYPE& value) d_isDirty = true; } else { - delta += name.length() + sizeof(MessagePropertyHeader); + delta += static_cast(name.length() + + sizeof(MessagePropertyHeader)); if (0 == numProperties()) { // If its the 1st property, also include the size of struct // 'MessagePropertiesHeader'. diff --git a/src/groups/bmq/bmqp/bmqp_messageproperties.t.cpp b/src/groups/bmq/bmqp/bmqp_messageproperties.t.cpp index adabe5c3e..5e506f0f7 100644 --- a/src/groups/bmq/bmqp/bmqp_messageproperties.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_messageproperties.t.cpp @@ -142,12 +142,16 @@ class PropertyValueStreamOutVisitor { void operator()(const bsl::string& value) { - bdlbb::BlobUtil::append(d_blob_p, value.c_str(), value.length()); + bdlbb::BlobUtil::append(d_blob_p, + value.c_str(), + static_cast(value.length())); } void operator()(const bsl::vector& value) { - bdlbb::BlobUtil::append(d_blob_p, value.data(), value.size()); + bdlbb::BlobUtil::append(d_blob_p, + value.data(), + static_cast(value.size())); } }; @@ -184,7 +188,8 @@ void populateProperties(bmqp::MessageProperties* properties, case 1: { osstr << "charPropName" << i << bsl::ends; - char value = bsl::numeric_limits::max() / i; + char value = static_cast(bsl::numeric_limits::max() / + i); ASSERT_EQ_D(i, 0, p.setPropertyAsChar(osstr.str(), value)); @@ -199,7 +204,8 @@ void populateProperties(bmqp::MessageProperties* properties, case 2: { osstr << "shortPropName" << i << bsl::ends; - short value = bsl::numeric_limits::max() / i; + short value = static_cast( + bsl::numeric_limits::max() / i); ASSERT_EQ_D(i, 0, p.setPropertyAsShort(osstr.str(), value)); @@ -214,7 +220,7 @@ void populateProperties(bmqp::MessageProperties* properties, case 3: { osstr << "intPropName" << i << bsl::ends; - int value = bsl::numeric_limits::max() / i; + int value = static_cast(bsl::numeric_limits::max() / i); ASSERT_EQ_D(i, 0, p.setPropertyAsInt32(osstr.str(), value)); @@ -402,7 +408,7 @@ void encode(bdlbb::Blob* blob, const PropertyMap& pmap) mpsh->setHeaderSize(sizeof(bmqp::MessagePropertiesHeader)); mpsh->setMessagePropertyHeaderSize(sizeof(bmqp::MessagePropertyHeader)); - mpsh->setNumProperties(pmap.size()); + mpsh->setNumProperties(static_cast(pmap.size())); totalSize += sizeof(bmqp::MessagePropertiesHeader); @@ -411,8 +417,8 @@ void encode(bdlbb::Blob* blob, const PropertyMap& pmap) const PropertyTypeSizeVariantPair& tsvPair = cit->second; bmqp::MessagePropertyHeader mph; mph.setPropertyType(tsvPair.first.first); - mph.setPropertyNameLength(cit->first.length()); - mph.setPropertyValueLength(tsvPair.first.second); + mph.setPropertyNameLength(static_cast(cit->first.length())); + mph.setPropertyValueLength(static_cast(tsvPair.first.second)); bdlbb::BlobUtil::append(blob, reinterpret_cast(&mph), @@ -423,12 +429,14 @@ void encode(bdlbb::Blob* blob, const PropertyMap& pmap) // Second pass. for (PropertyMapConstIter cit = pmap.begin(); cit != pmap.end(); ++cit) { const PropertyTypeSizeVariantPair& tsvPair = cit->second; - bdlbb::BlobUtil::append(blob, cit->first.c_str(), cit->first.length()); - totalSize += cit->first.length(); + bdlbb::BlobUtil::append(blob, + cit->first.c_str(), + static_cast(cit->first.length())); + totalSize += static_cast(cit->first.length()); PropertyValueStreamOutVisitor visitor(blob); tsvPair.second.apply(visitor); - totalSize += tsvPair.first.second; + totalSize += static_cast(tsvPair.first.second); } ASSERT_EQ(totalSize, b.length()); @@ -521,8 +529,9 @@ static void test1_breathingTest() ASSERT_EQ(true, p.remove("timestamp", &ptype)); ASSERT_EQ(bmqt::PropertyType::e_INT64, ptype); - totalLen -= (sizeof(bmqp::MessagePropertyHeader) + - bsl::strlen("timestamp") + sizeof(bsls::Types::Int64)); + totalLen -= static_cast(sizeof(bmqp::MessagePropertyHeader) + + bsl::strlen("timestamp") + + sizeof(bsls::Types::Int64)); ASSERT_EQ(p.numProperties(), 1); ASSERT_EQ(p.hasProperty("category"), true);