From abf6c88a8610929466664a1ac75eaea913aa91a2 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 17 Jan 2025 18:56:34 +0100 Subject: [PATCH] JNI: Extract size check from fromContainer Addresses header review comment. Change-Id: I302ae22da197fa8c317f0a4749d15b07fb5d0078 Reviewed-by: Marc Mutz (cherry picked from commit b5538a5a0ebf9bd9a155b857c385c764c30eabae) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qjniarray.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qjniarray.h b/src/corelib/kernel/qjniarray.h index 3e6976296b9..fdbe05c534c 100644 --- a/src/corelib/kernel/qjniarray.h +++ b/src/corelib/kernel/qjniarray.h @@ -480,8 +480,7 @@ public: template = true> static auto fromContainer(Container &&container) { - if (!q20::in_range(std::size(container))) - qWarning("QJniArray::fromContainer: Container is too large for Java and will be truncated!"); + verifySize(std::size(container)); using ElementType = typename std::remove_reference_t::value_type; if constexpr (std::is_base_of_v, std::remove_pointer_t>) { @@ -605,6 +604,13 @@ protected: void swap(QJniArrayBase &other) noexcept { m_object.swap(other.m_object); } private: + template + static void verifySize(container_size_type size) + { + if (!q20::in_range(size)) + qWarning("QJniArray::fromContainer: Container is too large for Java and will be truncated!"); + } + QJniObject m_object; };