Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Fix a possible UB in kislager::do_static_cast

Dmitry Kazakovf4e2b0070e06
diff --git a/libs/global/KisLager.h b/libs/global/KisLager.h
index e2dba92496..11d338b588 100644
--- a/libs/global/KisLager.h
+++ b/libs/global/KisLager.h
@@ -65,9 +65,9 @@ constexpr auto scale_real_to_int = [] (qreal multiplier) {
);
};
-template <typename Src, typename Dst>
+template <typename Src, typename Dst, typename SrcConstRef = std::add_lvalue_reference_t<std::add_const_t<Src>>>
auto do_static_cast = lager::lenses::getset(
- [] (Src value) { return static_cast<Dst>(value); },
+ [] (SrcConstRef value) { return static_cast<Dst>(value); },
[] (Src, Dst value) { return static_cast<Src>(value); }
);