Skip to content

Commit

Permalink
Fix: -Wconversion and other warnings (#281)
Browse files Browse the repository at this point in the history
* Fix mwc and mqb conversion warnings

* Fix bmqstoragetool warnings

Signed-off-by: Anton Pryakhin <[email protected]>
  • Loading branch information
waldgange authored May 16, 2024
1 parent e1ea3db commit e0f5ee1
Show file tree
Hide file tree
Showing 32 changed files with 197 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ static void test1_breathingTest()
// Empty parameters
CommandLineArguments arguments;
Parameters params(arguments, s_allocator_p);
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(s_allocator_p),
s_allocator_p);
bslma::ManagedPtr<FileManager> fileManager(new (*s_allocator_p)
FileManagerMock(),
s_allocator_p);

bslma::ManagedPtr<CommandProcessor> cmdProcessor =
CommandProcessorFactory::createCommandProcessor(&params,
Expand Down
5 changes: 2 additions & 3 deletions src/applications/bmqstoragetool/m_bmqstoragetool_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ Filters::Filters(const bsl::vector<bsl::string>& queueKeys,
const QueueMap& queueMap,
const bsls::Types::Int64 timestampGt,
const bsls::Types::Int64 timestampLt,
bsl::ostream& ostream,
bslma::Allocator* allocator)
: d_queueKeys(allocator)
, d_timestampGt(timestampGt)
, d_timestampLt(timestampLt)
, d_timestampGt(static_cast<bsls::Types::Uint64>(timestampGt))
, d_timestampLt(static_cast<bsls::Types::Uint64>(timestampLt))
{
// Fill internal structures
if (!queueKeys.empty()) {
Expand Down
5 changes: 2 additions & 3 deletions src/applications/bmqstoragetool/m_bmqstoragetool_filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Filters {
private:
// DATA
bsl::unordered_set<mqbu::StorageKey> d_queueKeys;
const bsls::Types::Int64 d_timestampGt;
const bsls::Types::Int64 d_timestampLt;
const bsls::Types::Uint64 d_timestampGt;
const bsls::Types::Uint64 d_timestampLt;

public:
// CREATORS
Expand All @@ -55,7 +55,6 @@ class Filters {
const QueueMap& queueMap,
const bsls::Types::Int64 timestampGt,
const bsls::Types::Int64 timestampLt,
bsl::ostream& ostream,
bslma::Allocator* allocator);

// MANIPULATORS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ void JournalFileProcessor::process()
d_parameters->d_queueMap,
d_parameters->d_timestampGt,
d_parameters->d_timestampLt,
d_ostream,
d_allocator_p);

bool stopSearch = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void test1_breathingTest()
Parameters params(s_allocator_p);
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand Down Expand Up @@ -151,7 +151,7 @@ static void test2_searchGuidTest()
}
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand Down Expand Up @@ -208,7 +208,7 @@ static void test3_searchNonExistingGuidTest()

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand Down Expand Up @@ -285,7 +285,7 @@ static void test4_searchExistingAndNonExistingGuidTest()

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand Down Expand Up @@ -338,7 +338,7 @@ static void test5_searchOutstandingMessagesTest()
params.d_outstanding = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand All @@ -359,9 +359,10 @@ static void test5_searchOutstandingMessagesTest()

expectedStream << outstandingGUIDS.size() << " message GUID(s) found."
<< bsl::endl;
float messageCount = k_NUM_RECORDS / 3.0;
float outstandingRatio = float(outstandingGUIDS.size()) / messageCount *
100.0;
const size_t messageCount = k_NUM_RECORDS / 3;
const float outstandingRatio = static_cast<float>(
outstandingGUIDS.size()) /
static_cast<float>(messageCount) * 100.0f;
expectedStream << "Outstanding ratio: " << outstandingRatio << "% ("
<< outstandingGUIDS.size() << "/" << messageCount << ")"
<< bsl::endl;
Expand Down Expand Up @@ -397,7 +398,7 @@ static void test6_searchConfirmedMessagesTest()
params.d_confirmed = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand All @@ -417,9 +418,10 @@ static void test6_searchConfirmedMessagesTest()
}
expectedStream << confirmedGUIDS.size() << " message GUID(s) found."
<< bsl::endl;
float messageCount = k_NUM_RECORDS / 3.0;
float outstandingRatio = float(messageCount - confirmedGUIDS.size()) /
messageCount * 100.0;
const size_t messageCount = k_NUM_RECORDS / 3;
const float outstandingRatio = static_cast<float>(messageCount -
confirmedGUIDS.size()) /
static_cast<float>(messageCount) * 100.0f;
expectedStream << "Outstanding ratio: " << outstandingRatio << "% ("
<< (messageCount - confirmedGUIDS.size()) << "/"
<< messageCount << ")" << bsl::endl;
Expand Down Expand Up @@ -458,7 +460,7 @@ static void test7_searchPartiallyConfirmedMessagesTest()
params.d_partiallyConfirmed = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand All @@ -478,9 +480,10 @@ static void test7_searchPartiallyConfirmedMessagesTest()
}
expectedStream << partiallyConfirmedGUIDS.size()
<< " message GUID(s) found." << bsl::endl;
float messageCount = ceil(k_NUM_RECORDS / 3.0);
float outstandingRatio = float(partiallyConfirmedGUIDS.size() + 1) /
messageCount * 100.0;
const size_t messageCount = (k_NUM_RECORDS + 2) / 3;
const float outstandingRatio = static_cast<float>(
partiallyConfirmedGUIDS.size() + 1) /
static_cast<float>(messageCount) * 100.0f;
expectedStream << "Outstanding ratio: " << outstandingRatio << "% ("
<< partiallyConfirmedGUIDS.size() + 1 << "/" << messageCount
<< ")" << bsl::endl;
Expand Down Expand Up @@ -519,7 +522,7 @@ static void test8_searchMessagesByQueueKeyTest()
params.d_queueKey.push_back(queueKey1);
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand Down Expand Up @@ -585,7 +588,7 @@ static void test9_searchMessagesByQueueNameTest()

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand Down Expand Up @@ -655,7 +658,7 @@ static void test10_searchMessagesByQueueNameAndQueueKeyTest()

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand Down Expand Up @@ -707,7 +710,7 @@ static void test11_searchMessagesByTimestamp()
params.d_timestampLt = ts2;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Get GUIDs of messages with matching timestamps and prepare expected
Expand Down Expand Up @@ -770,7 +773,7 @@ static void test12_printMessagesDetailsTest()
params.d_details = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand All @@ -788,7 +791,7 @@ static void test12_printMessagesDetailsTest()
const char* messageRecordCaption = "MESSAGE Record";
const char* confirmRecordCaption = "CONFIRM Record";
const char* deleteRecordCaption = "DELETE Record";
for (int i = 0; i < confirmedGUIDS.size(); i++) {
for (size_t i = 0; i < confirmedGUIDS.size(); i++) {
// Check Message type
size_t foundIdx = resultString.find(messageRecordCaption, startIdx);
ASSERT_D(messageRecordCaption, (foundIdx != bsl::string::npos));
Expand Down Expand Up @@ -897,7 +900,7 @@ static void test13_searchMessagesWithPayloadDumpTest()
params.d_dumpPayload = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);
EXPECT_CALL(static_cast<FileManagerMock&>(*fileManager),
dataFileIterator())
Expand Down Expand Up @@ -926,7 +929,7 @@ static void test13_searchMessagesWithPayloadDumpTest()
bsl::swap(confirmedGUIDS[1], confirmedGUIDS[2]);

// Check that substrings are present in resultStream in correct order
for (int i = 0; i < k_NUM_MSGS; i++) {
for (unsigned int i = 0; i < k_NUM_MSGS; i++) {
// Check GUID
bmqt::MessageGUID guid = confirmedGUIDS.at(i);
mwcu::MemOutStream ss(s_allocator_p);
Expand Down Expand Up @@ -978,7 +981,7 @@ static void test14_summaryTest()
params.d_summary = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(journalFile, s_allocator_p),
new (*s_allocator_p) FileManagerMock(journalFile),
s_allocator_p);

// Run search
Expand Down Expand Up @@ -1119,7 +1122,7 @@ static void test15_timestampSearchTest()
// Move the iterator to the beginning of the file
ASSERT_EQ(journalFileIt.nextRecord(), 1);
ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts), 1);
ASSERT_EQ(journalFileIt.recordIndex(), 0);
ASSERT_EQ(journalFileIt.recordIndex(), 0U);
ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts);
ASSERT(!journalFileIt.isReverseMode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ static void test1_breathingTest()
// Empty parameters
CommandLineArguments arguments;
Parameters params(arguments, s_allocator_p);
bslma::ManagedPtr<FileManager> fileManager(
new (*s_allocator_p) FileManagerMock(s_allocator_p),
s_allocator_p);
bslma::ManagedPtr<FileManager> fileManager(new (*s_allocator_p)
FileManagerMock(),
s_allocator_p);

bsl::shared_ptr<SearchResult> searchResult =
SearchResultFactory::createSearchResult(&params,
Expand Down
19 changes: 12 additions & 7 deletions src/applications/bmqstoragetool/m_bmqstoragetool_testutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,13 @@ char* addDataRecords(bslma::Allocator* ta,
// the padding that we need for each record.

for (unsigned int i = 0; i < numMessages; i++) {
unsigned int optionsLen = bsl::strlen(messages[i].d_options_p);
unsigned int optionsLen = static_cast<unsigned int>(
bsl::strlen(messages[i].d_options_p));
BSLS_ASSERT_OPT(0 == optionsLen % bmqp::Protocol::k_WORD_SIZE);

unsigned int appDataLen = bsl::strlen(messages[i].d_appData_p);
int appDataPadding = 0;
unsigned int appDataLen = static_cast<unsigned int>(
bsl::strlen(messages[i].d_appData_p));
int appDataPadding = 0;
bmqp::ProtocolUtil::calcNumDwordsAndPadding(&appDataPadding,
appDataLen + optionsLen +
dhSize);
Expand Down Expand Up @@ -631,12 +633,14 @@ char* addDataRecords(bslma::Allocator* ta,
currPos += sizeof(DataFileHeader);

for (unsigned int i = 0; i < numMessages; i++) {
messageOffsets.push_back(currPos / bmqp::Protocol::k_DWORD_SIZE);
messageOffsets.push_back(
static_cast<unsigned int>(currPos / bmqp::Protocol::k_DWORD_SIZE));

OffsetPtr<DataHeader> dh(block, currPos);
new (dh.get()) DataHeader();

unsigned int optionsLen = bsl::strlen(messages[i].d_options_p);
unsigned int optionsLen = static_cast<unsigned int>(
bsl::strlen(messages[i].d_options_p));
dh->setOptionsWords(optionsLen / bmqp::Protocol::k_WORD_SIZE);
currPos += sizeof(DataHeader);

Expand All @@ -645,8 +649,9 @@ char* addDataRecords(bslma::Allocator* ta,
currPos += optionsLen;
destination += optionsLen;

unsigned int appDataLen = bsl::strlen(messages[i].d_appData_p);
int appDataPad = 0;
unsigned int appDataLen = static_cast<unsigned int>(
bsl::strlen(messages[i].d_appData_p));
int appDataPad = 0;
bmqp::ProtocolUtil::calcNumDwordsAndPadding(&appDataPad,
appDataLen + optionsLen +
dhSize);
Expand Down
11 changes: 5 additions & 6 deletions src/applications/bmqstoragetool/m_bmqstoragetool_testutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class JournalFile {
const FileHeader& fileHeader() const;

/// Return value of timestamp incrementation.
const bsls::Types::Uint64 timestampIncrement() const;
bsls::Types::Uint64 timestampIncrement() const;

// MANIPULATORS

Expand Down Expand Up @@ -232,16 +232,15 @@ class FileManagerMock : public FileManager {
public:
// CREATORS

/// Constructor using the specified `allocator`.
explicit FileManagerMock(bslma::Allocator* allocator = 0)
/// Default constructor.
explicit FileManagerMock()
{
EXPECT_CALL(*this, dataFileIterator())
.WillRepeatedly(Return(&d_dataFileIt));
}

/// Constructor using the specified `journalFile` and `allocator`.
explicit FileManagerMock(const JournalFile& journalFile,
bslma::Allocator* allocator = 0)
explicit FileManagerMock(const JournalFile& journalFile)
: d_journalFileIt(&journalFile.mappedFileDescriptor(),
journalFile.fileHeader(),
false)
Expand Down Expand Up @@ -275,7 +274,7 @@ inline const FileHeader& JournalFile::fileHeader() const
return d_fileHeader;
}

inline const bsls::Types::Uint64 JournalFile::timestampIncrement() const
inline bsls::Types::Uint64 JournalFile::timestampIncrement() const
{
return d_timestampIncrement;
}
Expand Down
3 changes: 1 addition & 2 deletions src/groups/mqb/mqba/mqba_clientsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,7 @@ void ClientSession::tearDownImpl(bslmt::Semaphore* semaphore,
it != d_queueSessionManager.queues().end();
++it) {
if (!it->second.d_hasReceivedFinalCloseQueue) {
mqbi::Queue* queue = it->second.d_handle_p->queue();
BSLS_ASSERT_SAFE(queue);
BSLS_ASSERT_SAFE(it->second.d_handle_p->queue());

if (isBrokerShutdown ||
d_clientIdentity_p->clientType() ==
Expand Down
12 changes: 7 additions & 5 deletions src/groups/mqb/mqbblp/mqbblp_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2406,8 +2406,9 @@ void Cluster::loadNodesInfo(mqbcmd::NodeStatuses* out) const
nodeSession.clusterNode()->isAvailable());
}

int rc = mqbcmd::NodeStatus::fromInt(&node.status(),
nodeSession.nodeStatus());
BSLA_MAYBE_UNUSED const int rc = mqbcmd::NodeStatus::fromInt(
&node.status(),
nodeSession.nodeStatus());
BSLS_ASSERT_SAFE(!rc && "Unsupported node status");

const bsl::vector<int>& partitionVec = nodeSession.primaryPartitions();
Expand All @@ -2425,7 +2426,7 @@ void Cluster::loadElectorInfo(mqbcmd::ElectorInfo* out) const
// PRECONDITIONS
BSLS_ASSERT_SAFE(dispatcher()->inDispatcherThread(this));

int rc = mqbcmd::ElectorState::fromInt(
BSLA_MAYBE_UNUSED int rc = mqbcmd::ElectorState::fromInt(
&out->electorState(),
d_clusterData.electorInfo().electorState());
BSLS_ASSERT_SAFE(!rc && "Unsupported elector state");
Expand Down Expand Up @@ -2471,8 +2472,9 @@ void Cluster::loadPartitionsInfo(mqbcmd::PartitionsInfo* out) const
pi.primaryNode()->nodeDescription());
}
partitions[i].primaryLeaseId() = pi.primaryLeaseId();
int rc = mqbcmd::PrimaryStatus::fromInt(&partitions[i].primaryStatus(),
pi.primaryStatus());
BSLA_MAYBE_UNUSED const int rc = mqbcmd::PrimaryStatus::fromInt(
&partitions[i].primaryStatus(),
pi.primaryStatus());
BSLS_ASSERT_SAFE(!rc && "Unsupported primary status");
}
}
Expand Down
Loading

0 comments on commit e0f5ee1

Please sign in to comment.