From 382c87333f06e034506624901fc2030dee5681ef Mon Sep 17 00:00:00 2001 From: Liu Linsong Date: Thu, 15 Aug 2024 14:26:27 +0800 Subject: [PATCH] QEventDispatcherGlib: avoid potential integer overflow There is a fact that the value of sizeof(int) may be smaller than the value of sizeof(qsizetype). Now that the data type of the return value for function QList::size() is qsizetype, we should change the datatype of activeNotifierPos from int to qsizetype in case that it may overflow in the function socketNotifierSourceDispatch. And we should also change the data type of the iteration variable i from int to qsizetype for the same reason in the function unregisterSocketNotifier. Change-Id: I017d184aa046684c0af1c17c94fb83611706ffa3 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qeventdispatcher_glib.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp index 1e906c4b275..2573cdc2c8f 100644 --- a/src/corelib/kernel/qeventdispatcher_glib.cpp +++ b/src/corelib/kernel/qeventdispatcher_glib.cpp @@ -29,7 +29,7 @@ struct GSocketNotifierSource { GSource source; QList pollfds; - int activeNotifierPos; + qsizetype activeNotifierPos; }; static gboolean socketNotifierSourcePrepare(GSource *, gint *timeout) @@ -459,7 +459,7 @@ void QEventDispatcherGlib::unregisterSocketNotifier(QSocketNotifier *notifier) Q_D(QEventDispatcherGlib); - for (int i = 0; i < d->socketNotifierSource->pollfds.size(); ++i) { + for (qsizetype i = 0; i < d->socketNotifierSource->pollfds.size(); ++i) { GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds.at(i); if (p->socketNotifier == notifier) { // found it