Enable -Wconversion

This commit is contained in:
Nicolas Werner 2022-10-26 01:10:35 +02:00
parent 5be8298d0a
commit b28fa86e6a
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
23 changed files with 102 additions and 78 deletions

View File

@ -275,6 +275,7 @@ if(NOT MSVC)
"${CMAKE_CXX_FLAGS} \
-Wall \
-Wextra \
-Wconversion \
-pedantic \
-fsized-deallocation \
-fdiagnostics-color=always \

View File

@ -191,7 +191,7 @@ AliasEditingModel::makeCanonical(int row)
auto moveAlias = aliases.at(row).alias;
if (!aliasEvent.alias.empty()) {
for (qsizetype i = 0; i < aliases.size(); i++) {
for (int i = 0; i < aliases.size(); i++) {
if (moveAlias == aliases[i].alias) {
if (aliases[i].canonical) {
aliases[i].canonical = false;
@ -286,7 +286,7 @@ AliasEditingModel::toggleAdvertize(int row)
void
AliasEditingModel::updateAlias(std::string alias, std::string target)
{
for (qsizetype i = 0; i < aliases.size(); i++) {
for (int i = 0; i < aliases.size(); i++) {
auto &e = aliases[i];
if (e.alias == alias) {
e.published = (target == room_id);
@ -300,7 +300,7 @@ AliasEditingModel::updatePublishedAliases(std::vector<std::string> advAliases)
{
for (const auto &advAlias : advAliases) {
bool found = false;
for (qsizetype i = 0; i < aliases.size(); i++) {
for (int i = 0; i < aliases.size(); i++) {
auto &alias = aliases[i];
if (alias.alias == advAlias) {
alias.published = true;

View File

@ -3777,9 +3777,9 @@ Cache::spaces()
std::string_view room_data;
if (roomsDb_.get(txn, space_id, room_data)) {
RoomInfo tmp = nlohmann::json::parse(std::move(room_data)).get<RoomInfo>();
ret.insert(QString::fromUtf8(space_id.data(), (qsizetype)space_id.size()), tmp);
ret.insert(QString::fromUtf8(space_id.data(), (int)space_id.size()), tmp);
} else {
ret.insert(QString::fromUtf8(space_id.data(), (qsizetype)space_id.size()),
ret.insert(QString::fromUtf8(space_id.data(), (int)space_id.size()),
std::nullopt);
}
}
@ -4938,7 +4938,7 @@ to_json(nlohmann::json &obj, const GroupSessionData &msg)
void
from_json(const nlohmann::json &obj, GroupSessionData &msg)
{
msg.message_index = obj.at("message_index").get<uint64_t>();
msg.message_index = obj.at("message_index").get<uint32_t>();
msg.timestamp = obj.value("ts", 0ULL);
msg.trusted = obj.value("trust", true);

View File

@ -33,7 +33,7 @@ struct DeviceKeysToMsgIndex
// map from device key to message_index
// Using the device id is safe because we check for reuse on device list updates
// Using the device id makes our logic much easier to read.
std::map<std::string, uint64_t> deviceids;
std::map<std::string, uint32_t> deviceids;
};
struct SharedWithUsers
@ -45,8 +45,8 @@ struct SharedWithUsers
// Extra information associated with an outbound megolm session.
struct GroupSessionData
{
uint64_t message_index = 0;
uint64_t timestamp = 0;
uint32_t message_index = 0;
// If we got the session via key sharing or forwarding, we can usually trust it.
// If it came from asymmetric key backup, it is not trusted.

View File

@ -93,8 +93,8 @@ struct RoomInfo
//! Use the TimelineModel::lastMessage for an accurate timestamp.
uint64_t approximate_last_modification_ts = 0;
uint16_t highlight_count = 0;
uint16_t notification_count = 0;
uint64_t highlight_count = 0;
uint64_t notification_count = 0;
};
void

View File

@ -179,7 +179,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
static unsigned int prevNotificationCount = 0;
unsigned int notificationCount = 0;
for (const auto &room : sync.rooms.join) {
notificationCount += room.second.unread_notifications.notification_count;
notificationCount +=
static_cast<unsigned int>(room.second.unread_notifications.notification_count);
}
// HACK: If we had less notifications last time we checked, send an alert if the
@ -1064,12 +1065,15 @@ ChatPage::verifyOneTimeKeyCountAfterStartup()
}
std::map<std::string, uint16_t> key_counts;
auto count = 0;
std::uint64_t count = 0;
if (auto c = res.one_time_key_counts.find(mtx::crypto::SIGNED_CURVE25519);
c == res.one_time_key_counts.end()) {
key_counts[mtx::crypto::SIGNED_CURVE25519] = 0;
} else {
key_counts[mtx::crypto::SIGNED_CURVE25519] = c->second;
key_counts[mtx::crypto::SIGNED_CURVE25519] =
c->second > std::numeric_limits<std::uint16_t>::max()
? std::numeric_limits<std::uint16_t>::max()
: static_cast<std::uint16_t>(c->second);
count = c->second;
}

View File

@ -104,7 +104,8 @@ JdenticonRunnable::run()
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
try {
QSvgRenderer renderer{jdenticon->generate(m_key, m_requestedSize.width()).toUtf8()};
QSvgRenderer renderer{
jdenticon->generate(m_key, static_cast<std::uint16_t>(m_requestedSize.width())).toUtf8()};
renderer.render(&painter);
} catch (std::exception &e) {
nhlog::ui()->error(

View File

@ -169,8 +169,9 @@ MxcImageProvider::download(const QString &id,
mtx::http::ThumbOpts opts;
opts.mxc_url = "mxc://" + id.toStdString();
opts.width = requestedSize.width() > 0 ? requestedSize.width() : -1;
opts.height = requestedSize.height() > 0 ? requestedSize.height() : -1;
opts.width = static_cast<uint8_t>(requestedSize.width() > 0 ? requestedSize.width() : -1);
opts.height =
static_cast<uint8_t>(requestedSize.height() > 0 ? requestedSize.height() : -1);
opts.method = crop ? "crop" : "scale";
http::client()->get_thumbnail(
opts,

View File

@ -85,8 +85,9 @@ ReadReceiptsModel::addUsers(
auto newReceipts = users.size() - readReceipts_.size();
if (newReceipts > 0) {
beginInsertRows(
QModelIndex{}, readReceipts_.size(), readReceipts_.size() + newReceipts - 1);
beginInsertRows(QModelIndex{},
static_cast<int>(readReceipts_.size()),
static_cast<int>(readReceipts_.size() + newReceipts - 1));
for (const auto &user : users) {
QPair<QString, QDateTime> item = {QString::fromStdString(user.second),

View File

@ -354,8 +354,8 @@ utils::scaleImageToPixmap(const QImage &img, int size)
// Deprecated in 5.13: const double sz =
// std::ceil(QApplication::desktop()->screen()->devicePixelRatioF() * (double)size);
const double sz =
std::ceil(QGuiApplication::primaryScreen()->devicePixelRatio() * (double)size);
const int sz = static_cast<int>(
std::ceil(QGuiApplication::primaryScreen()->devicePixelRatio() * (double)size));
return QPixmap::fromImage(img.scaled(sz, sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
@ -376,8 +376,8 @@ utils::scaleDown(uint64_t maxWidth, uint64_t maxHeight, const QPixmap &source)
w = source.width();
h = source.height();
} else {
w = source.width() * minAspectRatio;
h = source.height() * minAspectRatio;
w = static_cast<int>(static_cast<double>(source.width()) * minAspectRatio);
h = static_cast<int>(static_cast<double>(source.height()) * minAspectRatio);
}
return source.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
@ -452,7 +452,7 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
const auto end = data.cend();
for (auto pos = data.cbegin(); pos < end;) {
auto tagStart = std::find(pos, end, '<');
buffer.append(pos, tagStart - pos);
buffer.append(pos, static_cast<int>(tagStart - pos));
if (tagStart == end)
break;
@ -460,14 +460,15 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
const auto tagNameEnd =
std::find_first_of(tagNameStart, end, tagNameEnds.begin(), tagNameEnds.end());
if (allowedTags.find(QByteArray(tagNameStart, tagNameEnd - tagNameStart).toLower()) ==
if (allowedTags.find(
QByteArray(tagNameStart, static_cast<int>(tagNameEnd - tagNameStart)).toLower()) ==
allowedTags.end()) {
// not allowed -> escape
buffer.append("&lt;");
pos = tagNameStart;
continue;
} else {
buffer.append(tagStart, tagNameEnd - tagStart);
buffer.append(tagStart, static_cast<int>(tagNameEnd - tagStart));
pos = tagNameEnd;
@ -492,7 +493,8 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
auto attrEnd = std::find_first_of(
attrStart, attrsEnd, attrNameEnds.begin(), attrNameEnds.end());
auto attrName = QByteArray(attrStart, attrEnd - attrStart).toLower();
auto attrName =
QByteArray(attrStart, static_cast<int>(attrEnd - attrStart)).toLower();
auto sanitizeValue = [&attrName](QByteArray val) {
if (attrName == QByteArrayLiteral("src") && !val.startsWith("mxc://"))
@ -520,8 +522,8 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
if (valueEnd == attrsEnd)
break;
auto val =
sanitizeValue(QByteArray(attrStart, valueEnd - attrStart));
auto val = sanitizeValue(QByteArray(
attrStart, static_cast<int>(valueEnd - attrStart)));
attrStart = consumeSpaces(valueEnd + 1);
if (!val.isEmpty()) {
buffer.append(' ');
@ -537,8 +539,8 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
if (valueEnd == attrsEnd)
break;
auto val =
sanitizeValue(QByteArray(attrStart, valueEnd - attrStart));
auto val = sanitizeValue(QByteArray(
attrStart, static_cast<int>(valueEnd - attrStart)));
attrStart = consumeSpaces(valueEnd + 1);
if (!val.isEmpty()) {
buffer.append(' ');
@ -553,8 +555,8 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
attrsEnd,
attrValueEnds.begin(),
attrValueEnds.end());
auto val =
sanitizeValue(QByteArray(attrStart, valueEnd - attrStart));
auto val = sanitizeValue(QByteArray(
attrStart, static_cast<int>(valueEnd - attrStart)));
attrStart = consumeSpaces(valueEnd);
if (val.contains('"'))
@ -772,15 +774,15 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
auto hash = hashQString(input);
// create a hue value based on the hash of the input.
// Adapted to make Nico blue
auto userHue =
static_cast<int>(static_cast<double>(hash - static_cast<uint32_t>(0x60'00'00'00)) /
std::numeric_limits<uint32_t>::max() * 360.);
auto userHue = static_cast<double>(hash - static_cast<uint32_t>(0x60'00'00'00)) /
std::numeric_limits<uint32_t>::max() * 360.;
// start with moderate saturation and lightness values.
auto sat = 230;
auto lightness = 125;
auto sat = 230.;
auto lightness = 125.;
// converting to a QColor makes the luminance calc easier.
QColor inputColor = QColor::fromHsl(userHue, sat, lightness);
QColor inputColor = QColor::fromHsl(
static_cast<int>(userHue), static_cast<int>(sat), static_cast<int>(lightness));
// calculate the initial luminance and contrast of the
// generated color. It's possible that no additional
@ -798,7 +800,9 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
if (lightness >= 242 || lightness <= 13) {
qreal newSat = qBound(26.0, sat * 1.25, 242.0);
inputColor.setHsl(userHue, qFloor(newSat), lightness);
inputColor.setHsl(static_cast<int>(userHue),
static_cast<int>(qFloor(newSat)),
static_cast<int>(lightness));
auto tmpLum = luminance(inputColor);
auto higherContrast = computeContrast(tmpLum, backgroundLum);
if (higherContrast > contrast) {
@ -806,7 +810,9 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
sat = newSat;
} else {
newSat = qBound(26.0, sat / 1.25, 242.0);
inputColor.setHsl(userHue, qFloor(newSat), lightness);
inputColor.setHsl(static_cast<int>(userHue),
static_cast<int>(qFloor(newSat)),
static_cast<int>(lightness));
tmpLum = luminance(inputColor);
auto lowerContrast = computeContrast(tmpLum, backgroundLum);
if (lowerContrast > contrast) {
@ -817,7 +823,9 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
} else {
qreal newLightness = qBound(13.0, lightness * 1.25, 242.0);
inputColor.setHsl(userHue, sat, qFloor(newLightness));
inputColor.setHsl(static_cast<int>(userHue),
static_cast<int>(sat),
static_cast<int>(qFloor(newLightness)));
auto tmpLum = luminance(inputColor);
auto higherContrast = computeContrast(tmpLum, backgroundLum);
@ -829,7 +837,9 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
// otherwise, try going the other way instead.
} else {
newLightness = qBound(13.0, lightness / 1.25, 242.0);
inputColor.setHsl(userHue, sat, qFloor(newLightness));
inputColor.setHsl(static_cast<int>(userHue),
static_cast<int>(sat),
static_cast<int>(qFloor(newLightness)));
tmpLum = luminance(inputColor);
auto lowerContrast = computeContrast(tmpLum, backgroundLum);
if (lowerContrast > contrast) {
@ -888,8 +898,8 @@ utils::centerWidget(QWidget *widget, QWindow *parent)
}
auto findCenter = [childRect = widget->rect()](QRect hostRect) -> QPoint {
return QPoint(hostRect.center().x() - (childRect.width() * 0.5),
hostRect.center().y() - (childRect.height() * 0.5));
return QPoint(static_cast<int>(hostRect.center().x() - (childRect.width() * 0.5)),
static_cast<int>(hostRect.center().y() - (childRect.height() * 0.5)));
};
widget->move(findCenter(QGuiApplication::primaryScreen()->geometry()));
}

View File

@ -186,7 +186,7 @@ operator<<(QDBusArgument &arg, const QImage &image)
int channels = i.hasAlphaChannel() ? 4 : 3;
arg << i.depth() / channels;
arg << channels;
arg << QByteArray(reinterpret_cast<const char *>(i.bits()), i.sizeInBytes());
arg << QByteArray(reinterpret_cast<const char *>(i.bits()), static_cast<int>(i.sizeInBytes()));
arg.endStructure();
return arg;

View File

@ -1144,7 +1144,7 @@ handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyR
}
bool shouldSeeKeys = false;
uint64_t minimumIndex = -1;
uint32_t minimumIndex = -1;
if (sessionData->currently.keys.count(req.sender)) {
if (sessionData->currently.keys.at(req.sender)
.deviceids.count(req.content.requesting_device_id)) {

View File

@ -61,7 +61,7 @@ stacktraceHandler(int signum)
// see
// https://stackoverflow.com/questions/77005/how-to-automatically-generate-a-stacktrace-when-my-program-crashes/77336#77336
void *array[50];
size_t size;
int size;
// get void*'s for all entries on the stack
size = backtrace(array, 50);

View File

@ -153,7 +153,8 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
int count = 0;
auto end = spaceOrder_.lastChild(index.row() - 2);
for (int i = index.row() - 2; i <= end; i++)
count += spaceOrder_.tree[i].notificationCounts.notification_count;
count +=
static_cast<int>(spaceOrder_.tree[i].notificationCounts.notification_count);
return count;
}
case CommunitiesModel::Roles::HasLoudNotification: {

View File

@ -66,24 +66,24 @@ Permissions::canSend(int eventType)
int
Permissions::defaultLevel()
{
return pl.users_default;
return static_cast<int>(pl.users_default);
}
int
Permissions::redactLevel()
{
return pl.redact;
return static_cast<int>(pl.redact);
}
int
Permissions::changeLevel(int eventType)
{
return pl.state_level(to_string(
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType))));
return static_cast<int>(pl.state_level(to_string(
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType)))));
}
int
Permissions::sendLevel(int eventType)
{
return pl.event_level(to_string(
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType))));
return static_cast<int>(pl.event_level(to_string(
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType)))));
}
bool

View File

@ -679,7 +679,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
if (w == 0)
w = 1;
double prop = media_height(event) / (double)w;
double prop = (double)media_height(event) / (double)w;
return {prop > 0 ? prop : 1.};
}
@ -2881,7 +2881,7 @@ TimelineModel::pinnedMessages() const
return {};
QStringList list;
list.reserve((qsizetype)pinned->content.pinned.size());
list.reserve((int)pinned->content.pinned.size());
for (const auto &p : pinned->content.pinned)
list.push_back(QString::fromStdString(p));
@ -2912,7 +2912,7 @@ TimelineModel::widgetLinks() const
theme.clear();
user = QUrl::toPercentEncoding(user);
list.reserve((qsizetype)evs.size());
list.reserve((int)evs.size());
for (const auto &p : evs) {
auto url = QString::fromStdString(p.content.url);

View File

@ -406,7 +406,7 @@ public slots:
RoomSummary *parentSpace();
bool hasMentions() const { return highlight_count > 0; }
int notificationCount() const { return notification_count; }
int notificationCount() const { return static_cast<int>(notification_count); }
QString scrollTarget() const;

View File

@ -82,7 +82,7 @@ MxcAnimatedImage::startDownload()
std::string temp(ba.constData(), ba.size());
temp =
mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
buffer.setData(temp.data(), temp.size());
buffer.setData(temp.data(), static_cast<int>(temp.size()));
} else {
buffer.setData(device.readAll());
}

View File

@ -122,7 +122,7 @@ MxcMediaProxy::startDownload()
QByteArray ba = device.readAll();
std::string temp(ba.constData(), ba.size());
temp = mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
buffer.setData(temp.data(), temp.size());
buffer.setData(temp.data(), static_cast<int>(temp.size()));
} else {
buffer.setData(device.readAll());
}

View File

@ -132,7 +132,7 @@ RoomSettings::roomAvatarUrl()
int
RoomSettings::memberCount() const
{
return info_.member_count;
return static_cast<int>(info_.member_count);
}
void
@ -180,7 +180,8 @@ QStringList
RoomSettings::allowedRooms() const
{
QStringList rooms;
rooms.reserve(accessRules_.allow.size());
assert(accessRules_.allow.size() < std::numeric_limits<int>::max());
rooms.reserve(static_cast<int>(accessRules_.allow.size()));
for (const auto &e : accessRules_.allow) {
if (e.type == mtx::events::state::JoinAllowanceType::RoomMembership)
rooms.push_back(QString::fromStdString(e.room_id));

View File

@ -124,10 +124,10 @@ CallManager::CallManager(QObject *parent)
// Request new credentials close to expiry
// See https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
turnURIs_ = getTurnURIs(res);
uint32_t ttl = std::max(res.ttl, UINT32_C(3600));
uint32_t ttl = std::max(res.ttl, std::uint32_t{3600});
if (res.ttl < 3600)
nhlog::net()->warn("Setting ttl to 1 hour");
turnServerTimer_.setInterval(ttl * 1000 * 0.9);
turnServerTimer_.setInterval(std::chrono::seconds(ttl) * 10 / 9);
});
connect(&session_, &WebRTCSession::stateChanged, this, [this](webrtc::State state) {
@ -728,7 +728,8 @@ CallManager::devices(bool isVideo) const
isVideo ? UserSettings::instance()->camera() : UserSettings::instance()->microphone();
std::vector<std::string> devices =
CallDevices::instance().names(isVideo, defaultDevice.toStdString());
ret.reserve(devices.size());
assert(devices.size() < std::numeric_limits<int>::max());
ret.reserve(static_cast<int>(devices.size()));
std::transform(devices.cbegin(), devices.cend(), std::back_inserter(ret), [](const auto &d) {
return QString::fromStdString(d);
});
@ -867,7 +868,8 @@ CallManager::windowList()
}
#endif
QStringList ret;
ret.reserve(windows_.size());
assert(windows_.size() < std::numeric_limits<int>::max());
ret.reserve(static_cast<int>(windows_.size()));
for (const auto &w : windows_)
ret.append(w.first);

View File

@ -141,7 +141,8 @@ parseSDP(const std::string &sdp, GstWebRTCSDPType type)
{
GstSDPMessage *msg;
gst_sdp_message_new(&msg);
if (gst_sdp_message_parse_buffer((guint8 *)sdp.c_str(), sdp.size(), msg) == GST_SDP_OK) {
if (gst_sdp_message_parse_buffer((guint8 *)sdp.c_str(), static_cast<guint>(sdp.size()), msg) ==
GST_SDP_OK) {
return gst_webrtc_session_description_new(type, msg);
} else {
nhlog::ui()->error("WebRTC: failed to parse remote session description");
@ -371,9 +372,12 @@ getResolution(GstElement *pipe, const gchar *elementName, const gchar *padName)
std::pair<int, int>
getPiPDimensions(const std::pair<int, int> &resolution, int fullWidth, double scaleFactor)
{
int pipWidth = fullWidth * scaleFactor;
int pipHeight = static_cast<double>(resolution.second) / resolution.first * pipWidth;
return {pipWidth, pipHeight};
double pipWidth = fullWidth * scaleFactor;
double pipHeight = static_cast<double>(resolution.second) / resolution.first * pipWidth;
return {
static_cast<int>(std::ceil(pipWidth)),
static_cast<int>(std::ceil(pipHeight)),
};
}
void

View File

@ -4,6 +4,7 @@
#include <array>
#include <cassert>
#include <cmath>
#include <numbers>
#include <stdexcept>
#ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
@ -17,9 +18,6 @@
using namespace std::literals;
namespace {
template<class T>
T pi = 3.14159265358979323846;
constexpr std::array<char, 84> int_to_b83{
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~"};
@ -93,7 +91,7 @@ decode83(std::string_view value)
float
decodeMaxAC(int quantizedMaxAC) noexcept
{
return (quantizedMaxAC + 1) / 166.;
return static_cast<float>(quantizedMaxAC + 1) / 166.f;
}
float
@ -123,7 +121,7 @@ srgbToLinear(int value) noexcept
return std::pow((x + 0.055f) / 1.055f, 2.4f);
};
return srgbToLinearF(value / 255.f);
return srgbToLinearF(static_cast<float>(value) / 255.f);
}
int
@ -234,7 +232,7 @@ std::vector<float>
bases_for(size_t dimension, size_t components)
{
std::vector<float> bases(dimension * components, 0.f);
auto scale = pi<float> / float(dimension);
auto scale = std::numbers::pi_v<float> / float(dimension);
for (size_t x = 0; x < dimension; x++) {
for (size_t nx = 0; nx < size_t(components); nx++) {
bases[x * components + nx] = std::cos(scale * float(nx * x));
@ -323,7 +321,7 @@ encode(unsigned char *image, size_t width, size_t height, int components_x, int
srgbToLinear(image[3 * x + 2 + y * width * 3])};
// other half of normalization.
linear *= 1.f / width;
linear *= 1.f / static_cast<float>(width);
for (size_t ny = 0; ny < size_t(components_y); ny++) {
for (size_t nx = 0; nx < size_t(components_x); nx++) {
@ -339,7 +337,7 @@ encode(unsigned char *image, size_t width, size_t height, int components_x, int
// too far outside the float range.
for (size_t i = 0; i < factors.size(); i++) {
float normalisation = (i == 0) ? 1 : 2;
float scale = normalisation / (height);
float scale = normalisation / static_cast<float>(height);
factors[i] *= scale;
}