Fix some compiler warnings

This commit is contained in:
Nicolas Werner 2020-12-25 00:08:06 +00:00
parent 100b5e0371
commit 01e38d12ed
17 changed files with 51 additions and 50 deletions

View file

@ -579,6 +579,7 @@ endif()
if(WIN32)
add_executable (nheko WIN32 ${OS_BUNDLE} ${NHEKO_DEPS})
target_compile_definitions(nheko PRIVATE _WIN32_WINNT=0x0601)
else()
add_executable (nheko ${OS_BUNDLE} ${NHEKO_DEPS})
endif()

View file

@ -81,7 +81,7 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca
cache::saveImage(cacheKey.toStdString(), res);
}
emit proxy->avatarDownloaded(QByteArray(res.data(), res.size()));
emit proxy->avatarDownloaded(QByteArray(res.data(), (int)res.size()));
});
}

View file

@ -31,7 +31,7 @@ BlurhashResponse::run()
return;
}
QImage image(decoded.image.data(), decoded.width, decoded.height, QImage::Format_RGB32);
QImage image(decoded.image.data(), (int)decoded.width, (int)decoded.height, QImage::Format_RGB32);
m_image = image.copy();
emit finished();

View file

@ -675,7 +675,7 @@ Cache::image(lmdb::txn &txn, const std::string &url) const
if (!res)
return QByteArray();
return QByteArray(image.data(), image.size());
return QByteArray(image.data(), (int)image.size());
} catch (const lmdb::error &e) {
nhlog::db()->critical("image: {}, {}", e.what(), url);
}
@ -703,7 +703,7 @@ Cache::image(const QString &url) const
if (!res)
return QByteArray();
return QByteArray(image.data(), image.size());
return QByteArray(image.data(), (int)image.size());
} catch (const lmdb::error &e) {
nhlog::db()->critical("image: {} {}", e.what(), url.toStdString());
}
@ -1257,9 +1257,9 @@ Cache::saveState(const mtx::responses::Sync &res)
updatedInfo.tags = tmp.tags;
} catch (const json::exception &e) {
nhlog::db()->warn(
"failed to parse room info: room_id ({}), {}",
"failed to parse room info: room_id ({}), {}: {}",
room.first,
std::string(data.data(), data.size()));
std::string(data.data(), data.size()), e.what());
}
}
}
@ -1458,9 +1458,9 @@ Cache::singleRoomInfo(const std::string &room_id)
return tmp;
} catch (const json::exception &e) {
nhlog::db()->warn("failed to parse room info: room_id ({}), {}",
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
room_id,
std::string(data.data(), data.size()));
std::string(data.data(), data.size()), e.what());
}
}
@ -1492,9 +1492,9 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms)
room_info.emplace(QString::fromStdString(room), std::move(tmp));
} catch (const json::exception &e) {
nhlog::db()->warn("failed to parse room info: room_id ({}), {}",
nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}",
room,
std::string(data.data(), data.size()));
std::string(data.data(), data.size()), e.what());
}
} else {
// Check if the room is an invite.
@ -1508,9 +1508,9 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms)
std::move(tmp));
} catch (const json::exception &e) {
nhlog::db()->warn(
"failed to parse room info for invite: room_id ({}), {}",
"failed to parse room info for invite: room_id ({}), {}: {}",
room,
std::string(data.data(), data.size()));
std::string(data.data(), data.size()), e.what());
}
}
}
@ -2044,7 +2044,7 @@ Cache::getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb)
}
auto cursor = lmdb::cursor::open(txn, membersdb);
const int total = membersdb.size(txn);
const auto total = membersdb.size(txn);
std::size_t ii = 0;
std::string user_id;
@ -2327,7 +2327,7 @@ Cache::getRoomAvatar(const std::string &room_id)
txn.commit();
return QImage::fromData(QByteArray(response.data(), response.size()));
return QImage::fromData(QByteArray(response.data(), (int)response.size()));
}
std::vector<std::string>

View file

@ -61,7 +61,7 @@ struct RoomInfo
//! Whether or not the room is an invite.
bool is_invite = false;
//! Total number of members in the room.
int16_t member_count = 0;
size_t member_count = 0;
//! Who can access to the room.
mtx::events::state::JoinRule join_rule = mtx::events::state::JoinRule::Public;
bool guest_access = false;

View file

@ -439,7 +439,7 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
try {
http::client()->set_user(parse<User>(userid.toStdString()));
} catch (const std::invalid_argument &e) {
} catch (const std::invalid_argument &) {
nhlog::ui()->critical("bootstrapped with invalid user_id: {}",
userid.toStdString());
}

View file

@ -104,7 +104,7 @@ CommunitiesList::setTagsForRoom(const QString &room_id, const std::vector<std::s
}
// insert or remove the room from the tag as appropriate
std::string current_tag =
it->first.right(it->first.size() - strlen("tag:")).toStdString();
it->first.right(static_cast<int>(it->first.size() - strlen("tag:"))).toStdString();
if (std::find(tags.begin(), tags.end(), current_tag) != tags.end()) {
// the room has this tag
it->second->addRoom(room_id);
@ -246,7 +246,7 @@ CommunitiesList::fetchCommunityAvatar(const QString &id, const QString &avatarUr
cache::saveImage(opts.mxc_url, res);
auto data = QByteArray(res.data(), res.size());
auto data = QByteArray(res.data(), (int)res.size());
QPixmap pix;
pix.loadFromData(data);

View file

@ -117,7 +117,7 @@ CommunitiesListItem::resolveName() const
if (!name_.isEmpty())
return name_;
if (groupId_.startsWith("tag:"))
return groupId_.right(groupId_.size() - strlen("tag:"));
return groupId_.right(static_cast<int>(groupId_.size() - strlen("tag:")));
if (!groupId_.startsWith("+"))
return QString("Group"); // Group with no name or id.
@ -132,7 +132,7 @@ CommunitiesListItem::updateTooltip()
if (groupId_ == "world")
setToolTip(tr("All rooms"));
else if (is_tag()) {
QString tag = groupId_.right(groupId_.size() - strlen("tag:"));
QString tag = groupId_.right(static_cast<int>(groupId_.size() - strlen("tag:")));
if (tag == "m.favourite")
setToolTip(tr("Favourite rooms"));
else if (tag == "m.lowpriority")

View file

@ -225,7 +225,7 @@ LoginPage::onMatrixIdEntered()
try {
user = parse<User>(matrixid_input_->text().toStdString());
} catch (const std::exception &e) {
} catch (const std::exception &) {
showError(error_matrixid_label_,
"You have entered an invalid Matrix ID e.g @joe:matrix.org");
return;
@ -389,7 +389,7 @@ LoginPage::onLoginButtonClicked()
try {
user = parse<User>(matrixid_input_->text().toStdString());
} catch (const std::exception &e) {
} catch (const std::exception &) {
showError(error_matrixid_label_,
"You have entered an invalid Matrix ID e.g @joe:matrix.org");
return;

View file

@ -167,7 +167,7 @@ MainWindow::MainWindow(const QString profile, QWidget *parent)
try {
using namespace mtx::identifiers;
http::client()->set_user(parse<User>(user_id.toStdString()));
} catch (const std::invalid_argument &e) {
} catch (const std::invalid_argument &) {
nhlog::ui()->critical("bootstrapped with invalid user_id: {}",
user_id.toStdString());
}
@ -472,7 +472,7 @@ MainWindow::openReadReceiptsDialog(const QString &event_id)
try {
dialog->addUsers(cache::readReceipts(event_id, room_id));
} catch (const lmdb::error &e) {
} catch (const lmdb::error &) {
nhlog::db()->warn("failed to retrieve read receipts for {} {}",
event_id.toStdString(),
chat_page_->currentRoom().toStdString());

View file

@ -48,7 +48,7 @@ MxcImageResponse::run()
return;
}
auto data = QByteArray(res.data(), res.size());
auto data = QByteArray(res.data(), (int)res.size());
cache::saveImage(fileName, data);
m_image = utils::readImage(&data);
if (!m_image.isNull()) {
@ -92,7 +92,7 @@ MxcImageResponse::run()
temp = mtx::crypto::to_string(
mtx::crypto::decrypt_file(temp, m_encryptionInfo.value()));
auto data = QByteArray(temp.data(), temp.size());
auto data = QByteArray(temp.data(), (int)temp.size());
cache::saveImage(m_id, data);
m_image = utils::readImage(&data);
m_image.setText("original filename",

View file

@ -17,7 +17,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override
{
(void)parent;
return roomMembers_.size();
return (int)roomMembers_.size();
}
QVariant data(const QModelIndex &index, int role) const override;

View file

@ -244,20 +244,20 @@ utils::humanReadableFileSize(uint64_t bytes)
int
utils::levenshtein_distance(const std::string &s1, const std::string &s2)
{
const int nlen = s1.size();
const int hlen = s2.size();
const auto nlen = s1.size();
const auto hlen = s2.size();
if (hlen == 0)
return -1;
if (nlen == 1)
return s2.find(s1);
return (int)s2.find(s1);
std::vector<int> row1(hlen + 1, 0);
for (int i = 0; i < nlen; ++i) {
std::vector<int> row2(1, i + 1);
for (size_t i = 0; i < nlen; ++i) {
std::vector<int> row2(1, (int)i + 1);
for (int j = 0; j < hlen; ++j) {
for (size_t j = 0; j < hlen; ++j) {
const int cost = s1[i] != s2[j];
row2.push_back(
std::min(row1[j + 1] + 1, std::min(row2[j] + 1, row1[j] + cost)));
@ -381,15 +381,15 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
"caption", "/caption", "pre", "/pre", "span", "/span", "img", "/img"};
QByteArray data = rawStr.toUtf8();
QByteArray buffer;
const size_t length = data.size();
const int length = data.size();
buffer.reserve(length);
bool escapingTag = false;
for (size_t pos = 0; pos != length; ++pos) {
for (int pos = 0; pos != length; ++pos) {
switch (data.at(pos)) {
case '<': {
bool oneTagMatched = false;
size_t endPos = std::min(static_cast<size_t>(data.indexOf('>', pos)),
static_cast<size_t>(data.indexOf(' ', pos)));
const int endPos = static_cast<int>(std::min(static_cast<size_t>(data.indexOf('>', pos)),
static_cast<size_t>(data.indexOf(' ', pos))));
auto mid = data.mid(pos + 1, endPos - pos - 1);
for (const auto &tag : allowedTags) {
@ -543,7 +543,7 @@ utils::generateContrastingHexColor(const QString &input, const QString &backgrou
// Create a color for the input
auto hash = hashQString(input);
// create a hue value based on the hash of the input.
auto userHue = static_cast<int>(qAbs(hash % 360));
auto userHue = static_cast<int>(hash % 360);
// start with moderate saturation and lightness values.
auto sat = 220;
auto lightness = 125;

View file

@ -493,7 +493,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
roomNameLabel_ = new QLabel(QString::fromStdString(info_.name), this);
roomNameLabel_->setFont(largeFont);
auto membersLabel = new QLabel(tr("%n member(s)", "", info_.member_count), this);
auto membersLabel = new QLabel(tr("%n member(s)", "", (int)info_.member_count), this);
auto textLayout = new QVBoxLayout;
textLayout->addWidget(roomNameLabel_);

View file

@ -35,14 +35,14 @@ SuggestionsPopup::addRooms(const std::vector<RoomSearchResult> &rooms)
return;
}
const size_t layoutCount = layout_->count();
const size_t roomCount = rooms.size();
const int layoutCount = (int)layout_->count();
const int roomCount = (int)rooms.size();
// Remove the extra widgets from the layout.
if (roomCount < layoutCount)
removeLayoutItemsAfter(roomCount - 1);
for (size_t i = 0; i < roomCount; ++i) {
for (int i = 0; i < roomCount; ++i) {
auto item = layout_->itemAt(i);
// Create a new widget if there isn't already one in that
@ -62,7 +62,7 @@ SuggestionsPopup::addRooms(const std::vector<RoomSearchResult> &rooms)
resetSelection();
adjustSize();
resize(geometry().width(), 40 * rooms.size());
resize(geometry().width(), 40 * (int)rooms.size());
selectNextSuggestion();
}
@ -150,7 +150,7 @@ SuggestionsPopup::removeLayoutItemsAfter(size_t startingPos)
size_t posToRemove = layout_->count() - 1;
QLayoutItem *item;
while (startingPos <= posToRemove && (item = layout_->takeAt(posToRemove)) != nullptr) {
while (startingPos <= posToRemove && (item = layout_->takeAt((int)posToRemove)) != nullptr) {
delete item->widget();
delete item;

View file

@ -29,7 +29,7 @@ public:
friend uint qHash(const Index &i, uint seed = 0) noexcept
{
QtPrivate::QHashCombine hash;
seed = hash(seed, QByteArray::fromRawData(i.room.data(), i.room.size()));
seed = hash(seed, QByteArray::fromRawData(i.room.data(), (int)i.room.size()));
seed = hash(seed, i.idx);
return seed;
}
@ -46,8 +46,8 @@ public:
friend uint qHash(const IdIndex &i, uint seed = 0) noexcept
{
QtPrivate::QHashCombine hash;
seed = hash(seed, QByteArray::fromRawData(i.room.data(), i.room.size()));
seed = hash(seed, QByteArray::fromRawData(i.id.data(), i.id.size()));
seed = hash(seed, QByteArray::fromRawData(i.room.data(), (int)i.room.size()));
seed = hash(seed, QByteArray::fromRawData(i.id.data(), (int)i.id.size()));
return seed;
}

View file

@ -28,7 +28,7 @@ namespace std {
inline uint
qHash(const std::string &key, uint seed = 0)
{
return qHash(QByteArray::fromRawData(key.data(), key.length()), seed);
return qHash(QByteArray::fromRawData(key.data(), (int)key.length()), seed);
}
}
@ -1208,7 +1208,7 @@ TimelineModel::cacheMedia(QString eventId)
if (!file.open(QIODevice::WriteOnly))
return;
file.write(QByteArray(temp.data(), temp.size()));
file.write(QByteArray(temp.data(), (int)temp.size()));
file.close();
} catch (const std::exception &e) {
nhlog::ui()->warn("Error while saving file to: {}", e.what());
@ -1227,7 +1227,7 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
"multiple users. Second argument is the last user of that list. (If only one user is "
"typing, %1 is empty. You should still use it in your string though to silence Qt "
"warnings.)",
users.size());
(int)users.size());
if (users.empty()) {
return "";