QJniArray: assert that source container is not too large

Java still only can handle arrays of at most 2^31 entries, and the JNI
API for working with arrays is using types that are essentially int.
Assert that the container passed in is not larger than that.

Found during API review.

Task-number: QTBUG-119952
Change-Id: Ia0cbdbf098cf5b2c8ec50f0dd24dadf833bf40d0
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 23fb1c50eecaed2f5a3ebfe95e72892c054e4414)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2024-01-22 16:08:27 +01:00 committed by Qt Cherry-pick Bot
parent 7f9e5ccd55
commit ee895907f8

View File

@ -105,6 +105,9 @@ public:
>
static auto fromContainer(Container &&container)
{
Q_ASSERT_X(size_t(container.size()) <= size_t((std::numeric_limits<size_type>::max)()),
"QJniArray::fromContainer", "Container is too large for a Java array");
using ElementType = typename std::remove_reference_t<Container>::value_type;
if constexpr (std::disjunction_v<std::is_same<ElementType, jobject>,
std::is_same<ElementType, QJniObject>>) {