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 <thiago.macieira@intel.com>
This commit is contained in:
Liu Linsong 2024-08-15 14:26:27 +08:00
parent cef270265f
commit 382c87333f

View File

@ -29,7 +29,7 @@ struct GSocketNotifierSource
{
GSource source;
QList<GPollFDWithQSocketNotifier *> 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