From 4b51aedfc721eb05c79f2c12c4654a173640009d Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 13 Feb 2023 09:03:55 +0100 Subject: Fix sign compare offenders In a few places we compare signed and unsigned integers. In majority of cases it's because the iteration variable is declared as ssize_t but then in the for() loop it's compared against an unsigned int. But there is one case where the opposite happens (libvirt_virDomainSendKey()), or where an UINT_MAX (which is inherently unsigned) is compared against signed long. Also, use this opportunity to decrease scope of 'j' variable inside of libvirt_virDomainInterfaceAddresses(). Signed-off-by: Michal Privoznik --- libvirt-override.c | 23 +++++++++++++---------- libvirt-qemu-override.c | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libvirt-override.c b/libvirt-override.c index 1b9165f..0c198cb 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -347,7 +347,7 @@ libvirt_virDomainMemoryStats(PyObject *self ATTRIBUTE_UNUSED, virDomainPtr domain; PyObject *pyobj_domain; unsigned int nr_stats; - ssize_t i; + size_t i; virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR]; PyObject *info; PyObject *key = NULL, *val = NULL; @@ -1921,7 +1921,7 @@ virConnectCredCallbackWrapper(virConnectCredentialPtr cred, PyObject *pycb; PyObject *pyret = NULL; int ret = -1; - ssize_t i; + size_t i; LIBVIRT_ENSURE_THREAD_STATE; @@ -2030,7 +2030,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, auth.ncredtype = PyList_Size(pycredtype); if (auth.ncredtype) { - ssize_t i; + size_t i; if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0) return PyErr_NoMemory(); for (i = 0; i < auth.ncredtype; i++) { @@ -5240,7 +5240,7 @@ libvirt_virDomainInterfaceAddresses(PyObject *self ATTRIBUTE_UNUSED, unsigned int source; unsigned int flags; int ifaces_count = 0; - ssize_t i, j; + ssize_t i; if (!PyArg_ParseTuple(args, (char *) "OII:virDomainInterfaceAddresses", &pyobj_domain, &source, &flags)) @@ -5262,6 +5262,7 @@ libvirt_virDomainInterfaceAddresses(PyObject *self ATTRIBUTE_UNUSED, virDomainInterfacePtr iface = ifaces[i]; PyObject *py_addrs = NULL; PyObject *py_iface = NULL; + size_t j; if (!(py_iface = PyDict_New())) goto error; @@ -7981,7 +7982,7 @@ libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED, int ret; ssize_t i; unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS]; - unsigned int nkeycodes; + int nkeycodes; if (!PyArg_ParseTuple(args, (char *)"OiiOII:virDomainSendKey", &pyobj_domain, &codeset, &holdtime, &pyobj_list, @@ -8504,7 +8505,7 @@ libvirt_virDomainCreateWithFiles(PyObject *self ATTRIBUTE_UNUSED, unsigned int flags; unsigned int nfiles; int *files = NULL; - ssize_t i; + size_t i; if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainCreateWithFiles", &pyobj_domain, &pyobj_files, &flags)) @@ -8553,7 +8554,7 @@ libvirt_virDomainCreateXMLWithFiles(PyObject *self ATTRIBUTE_UNUSED, unsigned int flags; unsigned int nfiles; int *files = NULL; - ssize_t i; + size_t i; if (!PyArg_ParseTuple(args, (char *)"OzOI:virDomainCreateXMLWithFiles", &pyobj_conn, &xmlDesc, &pyobj_files, &flags)) @@ -8603,7 +8604,8 @@ libvirt_virDomainFSFreeze(PyObject *self ATTRIBUTE_UNUSED, unsigned int flags; unsigned int nmountpoints = 0; char **mountpoints = NULL; - ssize_t i = 0, j; + size_t i = 0; + size_t j = 0; if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainFSFreeze", &pyobj_domain, &pyobj_list, &flags)) @@ -8650,7 +8652,8 @@ libvirt_virDomainFSThaw(PyObject *self ATTRIBUTE_UNUSED, unsigned int flags; unsigned int nmountpoints = 0; char **mountpoints = NULL; - ssize_t i = 0, j; + size_t i = 0; + size_t j = 0; if (!PyArg_ParseTuple(args, (char *)"OOI:virDomainFSThaw", &pyobj_domain, &pyobj_list, &flags)) @@ -10806,7 +10809,7 @@ libvirt_virDomainFDAssociate(PyObject *self ATTRIBUTE_UNUSED, unsigned int flags; unsigned int nfiles; int *files = NULL; - ssize_t i; + size_t i; if (!PyArg_ParseTuple(args, (char *)"OsOI:virDomainFDAssociate", &pyobj_domain, &name, &pyobj_files, &flags)) diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c index a554498..ef72d51 100644 --- a/libvirt-qemu-override.c +++ b/libvirt-qemu-override.c @@ -343,7 +343,7 @@ libvirt_qemu_virDomainQemuMonitorCommandWithFiles(PyObject *self ATTRIBUTE_UNUSE unsigned int noutfiles = 0; int *outfiles = NULL; char *result = NULL; - ssize_t i; + size_t i; PyObject *py_outfiles = NULL; PyObject *py_retval = NULL; int c_retval; -- cgit v1.2.1