summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qjniarray.h10
-rw-r--r--src/corelib/kernel/qjnitypes_impl.h8
2 files changed, 12 insertions, 6 deletions
diff --git a/src/corelib/kernel/qjniarray.h b/src/corelib/kernel/qjniarray.h
index c924f662ee4..6f710390385 100644
--- a/src/corelib/kernel/qjniarray.h
+++ b/src/corelib/kernel/qjniarray.h
@@ -11,8 +11,9 @@
#include <QtCore/qjniobject.h>
#include <iterator>
-#include <utility>
+#include <QtCore/q26numeric.h>
#include <QtCore/q20type_traits.h>
+#include <QtCore/q20utility.h>
#if defined(Q_QDOC)
using jsize = qint32;
@@ -479,9 +480,8 @@ public:
template <typename Container, if_compatible_source_container<Container> = true>
static auto fromContainer(Container &&container)
{
- Q_ASSERT_X(size_t(std::size(container)) <= size_t((std::numeric_limits<size_type>::max)()),
- "QJniArray::fromContainer", "Container is too large for a Java array");
-
+ if (!q20::in_range<size_type>(std::size(container)))
+ qWarning("QJniArray::fromContainer: Container is too large for Java and will be truncated!");
using ElementType = typename std::remove_reference_t<Container>::value_type;
if constexpr (std::is_base_of_v<std::remove_pointer_t<jobject>,
std::remove_pointer_t<ElementType>>) {
@@ -914,7 +914,7 @@ auto QJniArrayBase::makeObjectArray(List &&list)
return ResultType();
JNIEnv *env = QJniEnvironment::getJniEnv();
- const size_type length = size_type(std::size(list));
+ const size_type length = q26::saturate_cast<size_type>(std::size(list));
// this assumes that all objects in the list have the same class
jclass elementClass = nullptr;
diff --git a/src/corelib/kernel/qjnitypes_impl.h b/src/corelib/kernel/qjnitypes_impl.h
index a5ce38d1a8c..6e1ba45db83 100644
--- a/src/corelib/kernel/qjnitypes_impl.h
+++ b/src/corelib/kernel/qjnitypes_impl.h
@@ -5,7 +5,10 @@
#define QJNITYPES_IMPL_H
#include <QtCore/qstring.h>
+
+#include <QtCore/q26numeric.h>
#include <QtCore/q20type_traits.h>
+#include <QtCore/q20utility.h>
#if defined(Q_QDOC) || defined(Q_OS_ANDROID)
#include <jni.h>
@@ -19,7 +22,10 @@ namespace Detail
{
static inline jstring fromQString(const QString &string, JNIEnv *env)
{
- return env->NewString(reinterpret_cast<const jchar*>(string.constData()), string.length());
+ if (!q20::in_range<jsize>(string.size()))
+ qWarning("String is too large for a Java string and will be truncated");
+ const jsize length = q26::saturate_cast<jsize>(string.size());
+ return env->NewString(reinterpret_cast<const jchar*>(string.constData()), length);
}
static inline QString toQString(jstring string, JNIEnv *env)