Skip to content

Commit

Permalink
Fix: bmqp messageproperties Wconv warns (bloomberg#273)
Browse files Browse the repository at this point in the history
Signed-off-by: Melvin He <[email protected]>
Signed-off-by: Patrick M. Niedzielski <[email protected]>
  • Loading branch information
melvinhe authored and alexander-e1off committed Oct 24, 2024
1 parent 9c52365 commit 12f6ba5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
26 changes: 17 additions & 9 deletions src/groups/bmq/bmqp/bmqp_messageproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(value.length()));
}

void operator()(const bsl::vector<char>& value)
{
bdlbb::BlobUtil::append(d_blob_p, value.data(), value.size());
bdlbb::BlobUtil::append(d_blob_p,
value.data(),
static_cast<int>(value.size()));
}
};

Expand Down Expand Up @@ -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<int>(it->first.length());
d_totalSize -= static_cast<int>(sizeof(MessagePropertyHeader));

if (p.d_offset) {
// Cannot remove the property since reading other properties needs
Expand Down Expand Up @@ -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<int>(cit->first.length()));
if (info.isExtended()) {
msgPropHeader->setPropertyValueLength(offset);
}
Expand All @@ -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<int>(cit->first.length());
offset += p.d_length;
}

Expand All @@ -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<int>(cit->first.length()));
totalSize += static_cast<int>(cit->first.length());

// Append property value.

Expand Down Expand Up @@ -1064,7 +1071,8 @@ bsl::ostream& MessageProperties::print(bsl::ostream& stream,
bdlma::LocalSequentialAllocator<k_MAX_BYTES_DUMP> lsa(0);

mwcu::MemOutStream os(k_MAX_BYTES_DUMP, &lsa);
os << bdlb::PrintStringHexDumper(&binaryVec[0], printSize);
os << bdlb::PrintStringHexDumper(&binaryVec[0],
static_cast<int>(printSize));

printer.printAttribute(nameOs.str().data(), os.str());
} break;
Expand Down
3 changes: 2 additions & 1 deletion src/groups/bmq/bmqp/bmqp_messageproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(name.length() +
sizeof(MessagePropertyHeader));
if (0 == numProperties()) {
// If its the 1st property, also include the size of struct
// 'MessagePropertiesHeader'.
Expand Down
35 changes: 22 additions & 13 deletions src/groups/bmq/bmqp/bmqp_messageproperties.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(value.length()));
}

void operator()(const bsl::vector<char>& value)
{
bdlbb::BlobUtil::append(d_blob_p, value.data(), value.size());
bdlbb::BlobUtil::append(d_blob_p,
value.data(),
static_cast<int>(value.size()));
}
};

Expand Down Expand Up @@ -184,7 +188,8 @@ void populateProperties(bmqp::MessageProperties* properties,

case 1: {
osstr << "charPropName" << i << bsl::ends;
char value = bsl::numeric_limits<char>::max() / i;
char value = static_cast<char>(bsl::numeric_limits<char>::max() /
i);

ASSERT_EQ_D(i, 0, p.setPropertyAsChar(osstr.str(), value));

Expand All @@ -199,7 +204,8 @@ void populateProperties(bmqp::MessageProperties* properties,

case 2: {
osstr << "shortPropName" << i << bsl::ends;
short value = bsl::numeric_limits<short>::max() / i;
short value = static_cast<short>(
bsl::numeric_limits<short>::max() / i);

ASSERT_EQ_D(i, 0, p.setPropertyAsShort(osstr.str(), value));

Expand All @@ -214,7 +220,7 @@ void populateProperties(bmqp::MessageProperties* properties,

case 3: {
osstr << "intPropName" << i << bsl::ends;
int value = bsl::numeric_limits<int>::max() / i;
int value = static_cast<int>(bsl::numeric_limits<int>::max() / i);

ASSERT_EQ_D(i, 0, p.setPropertyAsInt32(osstr.str(), value));

Expand Down Expand Up @@ -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<int>(pmap.size()));

totalSize += sizeof(bmqp::MessagePropertiesHeader);

Expand All @@ -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<int>(cit->first.length()));
mph.setPropertyValueLength(static_cast<int>(tsvPair.first.second));

bdlbb::BlobUtil::append(blob,
reinterpret_cast<const char*>(&mph),
Expand All @@ -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<int>(cit->first.length()));
totalSize += static_cast<int>(cit->first.length());

PropertyValueStreamOutVisitor visitor(blob);
tsvPair.second.apply(visitor);
totalSize += tsvPair.first.second;
totalSize += static_cast<int>(tsvPair.first.second);
}

ASSERT_EQ(totalSize, b.length());
Expand Down Expand Up @@ -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<int>(sizeof(bmqp::MessagePropertyHeader) +
bsl::strlen("timestamp") +
sizeof(bsls::Types::Int64));

ASSERT_EQ(p.numProperties(), 1);
ASSERT_EQ(p.hasProperty("category"), true);
Expand Down

0 comments on commit 12f6ba5

Please sign in to comment.