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
Pick-to: 6.7
Change-Id: Ia0cbdbf098cf5b2c8ec50f0dd24dadf833bf40d0
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
bb10
Volker Hilsheimer 2024-01-22 16:08:27 +01:00
parent cc5251ed59
commit 23fb1c50ee
1 changed files with 3 additions and 0 deletions

View File

@ -115,6 +115,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>>) {