diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b456b1a..ef8d52bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,6 +275,7 @@ if(NOT MSVC) "${CMAKE_CXX_FLAGS} \ -Wall \ -Wextra \ + -Wconversion \ -pedantic \ -fsized-deallocation \ -fdiagnostics-color=always \ diff --git a/src/AliasEditModel.cpp b/src/AliasEditModel.cpp index aee42dd1..3f24a7c5 100644 --- a/src/AliasEditModel.cpp +++ b/src/AliasEditModel.cpp @@ -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 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; diff --git a/src/Cache.cpp b/src/Cache.cpp index a83b73f7..4f1fed1c 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -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(); - 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(); + msg.message_index = obj.at("message_index").get(); msg.timestamp = obj.value("ts", 0ULL); msg.trusted = obj.value("trust", true); diff --git a/src/CacheCryptoStructs.h b/src/CacheCryptoStructs.h index 04e852b4..99e563bd 100644 --- a/src/CacheCryptoStructs.h +++ b/src/CacheCryptoStructs.h @@ -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 deviceids; + std::map 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. diff --git a/src/CacheStructs.h b/src/CacheStructs.h index 459ced5a..1f035fee 100644 --- a/src/CacheStructs.h +++ b/src/CacheStructs.h @@ -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 diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 756ef425..2ea987c2 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -179,7 +179,8 @@ ChatPage::ChatPage(QSharedPointer 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(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 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::max() + ? std::numeric_limits::max() + : static_cast(c->second); count = c->second; } diff --git a/src/JdenticonProvider.cpp b/src/JdenticonProvider.cpp index 22d2b887..e9a7c883 100644 --- a/src/JdenticonProvider.cpp +++ b/src/JdenticonProvider.cpp @@ -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(m_requestedSize.width())).toUtf8()}; renderer.render(&painter); } catch (std::exception &e) { nhlog::ui()->error( diff --git a/src/MxcImageProvider.cpp b/src/MxcImageProvider.cpp index 3022ca3d..26ffb934 100644 --- a/src/MxcImageProvider.cpp +++ b/src/MxcImageProvider.cpp @@ -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(requestedSize.width() > 0 ? requestedSize.width() : -1); + opts.height = + static_cast(requestedSize.height() > 0 ? requestedSize.height() : -1); opts.method = crop ? "crop" : "scale"; http::client()->get_thumbnail( opts, diff --git a/src/ReadReceiptsModel.cpp b/src/ReadReceiptsModel.cpp index 2b1cdc74..f9de970b 100644 --- a/src/ReadReceiptsModel.cpp +++ b/src/ReadReceiptsModel.cpp @@ -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(readReceipts_.size()), + static_cast(readReceipts_.size() + newReceipts - 1)); for (const auto &user : users) { QPair item = {QString::fromStdString(user.second), diff --git a/src/Utils.cpp b/src/Utils.cpp index b92c6cce..c782fa48 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -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( + 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(static_cast(source.width()) * minAspectRatio); + h = static_cast(static_cast(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(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(tagNameEnd - tagNameStart)).toLower()) == allowedTags.end()) { // not allowed -> escape buffer.append("<"); pos = tagNameStart; continue; } else { - buffer.append(tagStart, tagNameEnd - tagStart); + buffer.append(tagStart, static_cast(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(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(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(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(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(static_cast(hash - static_cast(0x60'00'00'00)) / - std::numeric_limits::max() * 360.); + auto userHue = static_cast(hash - static_cast(0x60'00'00'00)) / + std::numeric_limits::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(userHue), static_cast(sat), static_cast(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(userHue), + static_cast(qFloor(newSat)), + static_cast(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(userHue), + static_cast(qFloor(newSat)), + static_cast(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(userHue), + static_cast(sat), + static_cast(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(userHue), + static_cast(sat), + static_cast(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(hostRect.center().x() - (childRect.width() * 0.5)), + static_cast(hostRect.center().y() - (childRect.height() * 0.5))); }; widget->move(findCenter(QGuiApplication::primaryScreen()->geometry())); } diff --git a/src/dbus/NhekoDBusApi.cpp b/src/dbus/NhekoDBusApi.cpp index 47fdca69..2367c27b 100644 --- a/src/dbus/NhekoDBusApi.cpp +++ b/src/dbus/NhekoDBusApi.cpp @@ -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(i.bits()), i.sizeInBytes()); + arg << QByteArray(reinterpret_cast(i.bits()), static_cast(i.sizeInBytes())); arg.endStructure(); return arg; diff --git a/src/encryption/Olm.cpp b/src/encryption/Olm.cpp index 03d0e983..7ada2f92 100644 --- a/src/encryption/Olm.cpp +++ b/src/encryption/Olm.cpp @@ -1144,7 +1144,7 @@ handle_key_request_message(const mtx::events::DeviceEventcurrently.keys.count(req.sender)) { if (sessionData->currently.keys.at(req.sender) .deviceids.count(req.content.requesting_device_id)) { diff --git a/src/main.cpp b/src/main.cpp index 83b4657a..3937c6b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp index ef023cee..96d090f7 100644 --- a/src/timeline/CommunitiesModel.cpp +++ b/src/timeline/CommunitiesModel.cpp @@ -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(spaceOrder_.tree[i].notificationCounts.notification_count); return count; } case CommunitiesModel::Roles::HasLoudNotification: { diff --git a/src/timeline/Permissions.cpp b/src/timeline/Permissions.cpp index 9fa833b7..78bb3cf6 100644 --- a/src/timeline/Permissions.cpp +++ b/src/timeline/Permissions.cpp @@ -66,24 +66,24 @@ Permissions::canSend(int eventType) int Permissions::defaultLevel() { - return pl.users_default; + return static_cast(pl.users_default); } int Permissions::redactLevel() { - return pl.redact; + return static_cast(pl.redact); } int Permissions::changeLevel(int eventType) { - return pl.state_level(to_string( - qml_mtx_events::fromRoomEventType(static_cast(eventType)))); + return static_cast(pl.state_level(to_string( + qml_mtx_events::fromRoomEventType(static_cast(eventType))))); } int Permissions::sendLevel(int eventType) { - return pl.event_level(to_string( - qml_mtx_events::fromRoomEventType(static_cast(eventType)))); + return static_cast(pl.event_level(to_string( + qml_mtx_events::fromRoomEventType(static_cast(eventType))))); } bool diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 5ffd7415..6cf361aa 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -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); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 2a04c9c9..8bf18f19 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -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(notification_count); } QString scrollTarget() const; diff --git a/src/ui/MxcAnimatedImage.cpp b/src/ui/MxcAnimatedImage.cpp index 8ecea7d9..7f7210e3 100644 --- a/src/ui/MxcAnimatedImage.cpp +++ b/src/ui/MxcAnimatedImage.cpp @@ -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(temp.size())); } else { buffer.setData(device.readAll()); } diff --git a/src/ui/MxcMediaProxy.cpp b/src/ui/MxcMediaProxy.cpp index 3676a74e..dadd4478 100644 --- a/src/ui/MxcMediaProxy.cpp +++ b/src/ui/MxcMediaProxy.cpp @@ -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(temp.size())); } else { buffer.setData(device.readAll()); } diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp index 546cda29..67be0bbb 100644 --- a/src/ui/RoomSettings.cpp +++ b/src/ui/RoomSettings.cpp @@ -132,7 +132,7 @@ RoomSettings::roomAvatarUrl() int RoomSettings::memberCount() const { - return info_.member_count; + return static_cast(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::max()); + rooms.reserve(static_cast(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)); diff --git a/src/voip/CallManager.cpp b/src/voip/CallManager.cpp index 5e711499..1bb1700f 100644 --- a/src/voip/CallManager.cpp +++ b/src/voip/CallManager.cpp @@ -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 devices = CallDevices::instance().names(isVideo, defaultDevice.toStdString()); - ret.reserve(devices.size()); + assert(devices.size() < std::numeric_limits::max()); + ret.reserve(static_cast(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::max()); + ret.reserve(static_cast(windows_.size())); for (const auto &w : windows_) ret.append(w.first); diff --git a/src/voip/WebRTCSession.cpp b/src/voip/WebRTCSession.cpp index b3e6bf26..706a69d9 100644 --- a/src/voip/WebRTCSession.cpp +++ b/src/voip/WebRTCSession.cpp @@ -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(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 getPiPDimensions(const std::pair &resolution, int fullWidth, double scaleFactor) { - int pipWidth = fullWidth * scaleFactor; - int pipHeight = static_cast(resolution.second) / resolution.first * pipWidth; - return {pipWidth, pipHeight}; + double pipWidth = fullWidth * scaleFactor; + double pipHeight = static_cast(resolution.second) / resolution.first * pipWidth; + return { + static_cast(std::ceil(pipWidth)), + static_cast(std::ceil(pipHeight)), + }; } void diff --git a/third_party/blurhash/blurhash.cpp b/third_party/blurhash/blurhash.cpp index 78f72f9b..7eb9c827 100644 --- a/third_party/blurhash/blurhash.cpp +++ b/third_party/blurhash/blurhash.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN @@ -17,9 +18,6 @@ using namespace std::literals; namespace { -template -T pi = 3.14159265358979323846; - constexpr std::array 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(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(value) / 255.f); } int @@ -234,7 +232,7 @@ std::vector bases_for(size_t dimension, size_t components) { std::vector bases(dimension * components, 0.f); - auto scale = pi / float(dimension); + auto scale = std::numbers::pi_v / 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(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(height); factors[i] *= scale; }