aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-09-18 10:11:13 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-09-20 20:44:32 +0000
commit1cb937f294f21713874d0115606dcb980577eea0 (patch)
tree4375eff0e02d6aa8c1a0dfa06f28f2a168788e09
parentbf7ea7d24fe48433c59a35bb3f64d5eb102e0cc8 (diff)
libshiboken/libpyside: Fix some static analysis warnings
- nullptr - narrowing integer conversions - else after return - Use auto - Missing move special functions Change-Id: Ib872481a46c8bb17592cdc1778ab3c4d9598c753 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> (cherry picked from commit b8f5e535dab255af228830c6d548ce730a7603d5) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 5591e683853595ae0ddf19834fcb98867653930d)
-rw-r--r--sources/pyside6/libpyside/class_property.cpp8
-rw-r--r--sources/pyside6/libpyside/dynamicqmetaobject.cpp4
-rw-r--r--sources/pyside6/libpyside/dynamicqmetaobject.h2
-rw-r--r--sources/pyside6/libpyside/feature_select.cpp4
-rw-r--r--sources/pyside6/libpyside/globalreceiverv2.cpp2
-rw-r--r--sources/pyside6/libpyside/pyside.cpp2
-rw-r--r--sources/pyside6/libpyside/pysideclassinfo.cpp2
-rw-r--r--sources/pyside6/libpyside/pysideclassinfo_p.h1
-rw-r--r--sources/pyside6/libpyside/pysideproperty.cpp8
-rw-r--r--sources/pyside6/libpyside/pysidesignal.cpp4
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp21
-rw-r--r--sources/shiboken6/libshiboken/basewrapper_p.h6
-rw-r--r--sources/shiboken6/libshiboken/bindingmanager.cpp16
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.cpp6
-rw-r--r--sources/shiboken6/libshiboken/sbkconverter_p.h2
-rw-r--r--sources/shiboken6/libshiboken/sbkenum.cpp4
16 files changed, 43 insertions, 49 deletions
diff --git a/sources/pyside6/libpyside/class_property.cpp b/sources/pyside6/libpyside/class_property.cpp
index c255ef1e9..0bf738c61 100644
--- a/sources/pyside6/libpyside/class_property.cpp
+++ b/sources/pyside6/libpyside/class_property.cpp
@@ -51,7 +51,7 @@ static PyType_Slot PyClassProperty_slots[] = {
{Py_tp_descr_get, reinterpret_cast<void *>(PyClassProperty_descr_get)},
{Py_tp_descr_set, reinterpret_cast<void *>(PyClassProperty_descr_set)},
{Py_tp_init, reinterpret_cast<void *>(PyClassProperty_tp_init)},
- {0, 0}
+ {0, nullptr}
};
static PyType_Spec PyClassProperty_spec = {
@@ -97,10 +97,8 @@ static int SbkObjectType_meta_setattro(PyObject *obj, PyObject *name, PyObject *
if (call_descr_set) {
// Call `class_property.__set__()` instead of replacing the `class_property`.
return Py_TYPE(descr)->tp_descr_set(descr, obj, value);
- } else {
- // Replace existing attribute.
- return PyType_Type.tp_setattro(obj, name, value);
- }
+ } // Replace existing attribute.
+ return PyType_Type.tp_setattro(obj, name, value);
}
} // extern "C"
diff --git a/sources/pyside6/libpyside/dynamicqmetaobject.cpp b/sources/pyside6/libpyside/dynamicqmetaobject.cpp
index a3a16b6a0..e16f1b3e4 100644
--- a/sources/pyside6/libpyside/dynamicqmetaobject.cpp
+++ b/sources/pyside6/libpyside/dynamicqmetaobject.cpp
@@ -181,8 +181,8 @@ int MetaObjectBuilder::indexOfProperty(const QByteArray &name) const
static bool checkMethodSignature(const QByteArray &signature)
{
// Common mistake not to add parentheses to the signature.
- const int openParen = signature.indexOf('(');
- const int closingParen = signature.lastIndexOf(')');
+ const auto openParen = signature.indexOf('(');
+ const auto closingParen = signature.lastIndexOf(')');
const bool ok = openParen != -1 && closingParen != -1 && openParen < closingParen;
if (!ok) {
const QByteArray message =
diff --git a/sources/pyside6/libpyside/dynamicqmetaobject.h b/sources/pyside6/libpyside/dynamicqmetaobject.h
index 311c545f5..d5bf12756 100644
--- a/sources/pyside6/libpyside/dynamicqmetaobject.h
+++ b/sources/pyside6/libpyside/dynamicqmetaobject.h
@@ -17,7 +17,7 @@ namespace PySide
class MetaObjectBuilder
{
- Q_DISABLE_COPY(MetaObjectBuilder)
+ Q_DISABLE_COPY_MOVE(MetaObjectBuilder)
public:
using EnumValue = QPair<QByteArray, int>;
using EnumValues = QList<EnumValue>;
diff --git a/sources/pyside6/libpyside/feature_select.cpp b/sources/pyside6/libpyside/feature_select.cpp
index 1c0fb451e..14c349c30 100644
--- a/sources/pyside6/libpyside/feature_select.cpp
+++ b/sources/pyside6/libpyside/feature_select.cpp
@@ -611,9 +611,9 @@ static QByteArrayList GetPropertyStringsMro(PyTypeObject *type)
auto res = QByteArrayList();
PyObject *mro = type->tp_mro;
- Py_ssize_t idx, n = PyTuple_GET_SIZE(mro);
+ const Py_ssize_t n = PyTuple_GET_SIZE(mro);
// We leave 'Shiboken.Object' and 'object' alone, therefore "n - 2".
- for (idx = 0; idx < n - 2; idx++) {
+ for (Py_ssize_t idx = 0; idx < n - 2; idx++) {
auto *subType = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, idx));
auto props = SbkObjectType_GetPropertyStrings(subType);
if (props != nullptr)
diff --git a/sources/pyside6/libpyside/globalreceiverv2.cpp b/sources/pyside6/libpyside/globalreceiverv2.cpp
index 301d7c535..ddbd082e8 100644
--- a/sources/pyside6/libpyside/globalreceiverv2.cpp
+++ b/sources/pyside6/libpyside/globalreceiverv2.cpp
@@ -33,7 +33,7 @@ size_t qHash(const GlobalReceiverKey &k, size_t seed)
class DynamicSlotDataV2
{
- Q_DISABLE_COPY(DynamicSlotDataV2)
+ Q_DISABLE_COPY_MOVE(DynamicSlotDataV2)
public:
DynamicSlotDataV2(PyObject *callback, GlobalReceiverV2 *parent);
~DynamicSlotDataV2();
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index f2a2f0cb9..3fab9c8e5 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -572,7 +572,7 @@ PyObject *getHiddenDataFromQObject(QObject *cppSelf, PyObject *self, PyObject *n
const char *cname = Shiboken::String::toCString(name);
uint cnameLen = qstrlen(cname);
- if (std::strncmp("__", cname, 2)) {
+ if (std::strncmp("__", cname, 2) != 0) {
const QMetaObject *metaObject = cppSelf->metaObject();
QList<QMetaMethod> signalList;
// Caution: This inserts a meta function or a signal into the instance dict.
diff --git a/sources/pyside6/libpyside/pysideclassinfo.cpp b/sources/pyside6/libpyside/pysideclassinfo.cpp
index 60413be20..e727e09c4 100644
--- a/sources/pyside6/libpyside/pysideclassinfo.cpp
+++ b/sources/pyside6/libpyside/pysideclassinfo.cpp
@@ -14,7 +14,7 @@
extern "C"
{
-static PyTypeObject *createClassInfoType(void)
+static PyTypeObject *createClassInfoType()
{
auto typeSlots =
PySide::ClassDecorator::Methods<PySide::ClassInfo::ClassInfoPrivate>::typeSlots();
diff --git a/sources/pyside6/libpyside/pysideclassinfo_p.h b/sources/pyside6/libpyside/pysideclassinfo_p.h
index 7d59e4be8..32878c86a 100644
--- a/sources/pyside6/libpyside/pysideclassinfo_p.h
+++ b/sources/pyside6/libpyside/pysideclassinfo_p.h
@@ -8,7 +8,6 @@
#include "pysideclassdecorator_p.h"
#include "pysideclassinfo.h"
-#include "pysideclassinfo.h"
#include <QtCore/QMetaObject>
diff --git a/sources/pyside6/libpyside/pysideproperty.cpp b/sources/pyside6/libpyside/pysideproperty.cpp
index 4bc5f5b16..8b14b2885 100644
--- a/sources/pyside6/libpyside/pysideproperty.cpp
+++ b/sources/pyside6/libpyside/pysideproperty.cpp
@@ -174,7 +174,7 @@ void PySidePropertyPrivate::metaCall(PyObject *source, QMetaObject::Call call, v
static PyObject *qpropertyTpNew(PyTypeObject *subtype, PyObject * /* args */, PyObject * /* kwds */)
{
- PySideProperty *me = reinterpret_cast<PySideProperty *>(subtype->tp_alloc(subtype, 0));
+ auto *me = reinterpret_cast<PySideProperty *>(subtype->tp_alloc(subtype, 0));
me->d = new PySidePropertyPrivate;
return reinterpret_cast<PyObject *>(me);
}
@@ -262,7 +262,7 @@ static void qpropertyDeAlloc(PyObject *self)
static PyObject *
_property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *reset, PyObject *del)
{
- PySideProperty *pold = reinterpret_cast<PySideProperty *>(old);
+ auto *pold = reinterpret_cast<PySideProperty *>(old);
PySidePropertyPrivate *pData = pold->d;
AutoDecRef type(PyObject_Type(old));
@@ -448,8 +448,8 @@ static PyObject *getFromType(PyTypeObject *type, PyObject *name)
attr = PyDict_GetItem(type->tp_dict, name);
if (!attr) {
PyObject *bases = type->tp_bases;
- int size = PyTuple_GET_SIZE(bases);
- for(int i=0; i < size; i++) {
+ const Py_ssize_t size = PyTuple_GET_SIZE(bases);
+ for (Py_ssize_t i = 0; i < size; ++i) {
PyObject *base = PyTuple_GET_ITEM(bases, i);
attr = getFromType(reinterpret_cast<PyTypeObject *>(base), name);
if (attr)
diff --git a/sources/pyside6/libpyside/pysidesignal.cpp b/sources/pyside6/libpyside/pysidesignal.cpp
index a31e6f618..dc2a20350 100644
--- a/sources/pyside6/libpyside/pysidesignal.cpp
+++ b/sources/pyside6/libpyside/pysidesignal.cpp
@@ -774,9 +774,9 @@ static PyObject *_getHomonymousMethod(PySideSignalInstance *inst)
auto signalName = inst->d->signalName;
Shiboken::AutoDecRef name(Shiboken::String::fromCString(signalName));
auto *mro = Py_TYPE(inst->d->source)->tp_mro;
- Py_ssize_t idx, n = PyTuple_GET_SIZE(mro);
+ const Py_ssize_t n = PyTuple_GET_SIZE(mro);
- for (idx = 0; idx < n; idx++) {
+ for (Py_ssize_t idx = 0; idx < n; idx++) {
auto *sub_type = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, idx));
auto *hom = PyDict_GetItem(sub_type->tp_dict, name);
PyObject *realFunc{};
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index 8a7069fca..cf31b064a 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -1239,11 +1239,10 @@ void makeValid(SbkObject *self)
// If has ref to other objects make all valid again
if (self->d->referredObjects) {
- RefCountMap &refCountMap = *(self->d->referredObjects);
- RefCountMap::iterator iter;
- for (auto it = refCountMap.begin(), end = refCountMap.end(); it != end; ++it) {
- if (Shiboken::Object::checkType(it->second))
- makeValid(reinterpret_cast<SbkObject *>(it->second));
+ const RefCountMap &refCountMap = *(self->d->referredObjects);
+ for (const auto &p : refCountMap) {
+ if (Shiboken::Object::checkType(p.second))
+ makeValid(reinterpret_cast<SbkObject *>(p.second));
}
}
}
@@ -1758,17 +1757,17 @@ std::string info(SbkObject *self)
}
if (self->d->referredObjects && !self->d->referredObjects->empty()) {
- Shiboken::RefCountMap &map = *self->d->referredObjects;
+ const Shiboken::RefCountMap &map = *self->d->referredObjects;
s << "referred objects.. ";
std::string lastKey;
- for (auto it = map.begin(), end = map.end(); it != end; ++it) {
- if (it->first != lastKey) {
+ for (const auto &p : map) {
+ if (p.first != lastKey) {
if (!lastKey.empty())
s << " ";
- s << '"' << it->first << "\" => ";
- lastKey = it->first;
+ s << '"' << p.first << "\" => ";
+ lastKey = p.first;
}
- Shiboken::AutoDecRef obj(PyObject_Str(it->second));
+ Shiboken::AutoDecRef obj(PyObject_Str(p.second));
s << String::toCString(obj) << ' ';
}
s << '\n';
diff --git a/sources/shiboken6/libshiboken/basewrapper_p.h b/sources/shiboken6/libshiboken/basewrapper_p.h
index fc3cc321c..e59647aad 100644
--- a/sources/shiboken6/libshiboken/basewrapper_p.h
+++ b/sources/shiboken6/libshiboken/basewrapper_p.h
@@ -30,14 +30,12 @@ using ChildrenList = std::set<SbkObject *>;
/// Structure used to store information about object parent and children.
struct ParentInfo
{
- /// Default ctor.
- ParentInfo() : parent(nullptr), hasWrapperRef(false) {}
/// Pointer to parent object.
- SbkObject *parent;
+ SbkObject *parent = nullptr;
/// List of object children.
ChildrenList children;
/// has internal ref
- bool hasWrapperRef;
+ bool hasWrapperRef = false;
};
} // namespace Shiboken
diff --git a/sources/shiboken6/libshiboken/bindingmanager.cpp b/sources/shiboken6/libshiboken/bindingmanager.cpp
index c56d7cb2c..459efab59 100644
--- a/sources/shiboken6/libshiboken/bindingmanager.cpp
+++ b/sources/shiboken6/libshiboken/bindingmanager.cpp
@@ -39,15 +39,15 @@ public:
}
#ifndef NDEBUG
- void dumpDotGraph()
+ void dumpDotGraph() const
{
std::ofstream file("/tmp/shiboken_graph.dot");
file << "digraph D {\n";
- for (auto i = m_edges.begin(), end = m_edges.end(); i != end; ++i) {
- auto *node1 = i->first;
- const NodeList &nodeList = i->second;
+ for (const auto &p : m_edges) {
+ auto *node1 = p.first;
+ const NodeList &nodeList = p.second;
for (const PyTypeObject *o : nodeList) {
auto *node2 = o;
file << '"' << node2->tp_name << "\" -> \""
@@ -321,7 +321,7 @@ PyObject *BindingManager::getOverride(const void *cptr,
}
if (method != nullptr) {
- PyObject *defaultMethod;
+ PyObject *defaultMethod{};
PyObject *mro = Py_TYPE(wrapper)->tp_mro;
int size = PyTuple_GET_SIZE(mro);
@@ -374,9 +374,9 @@ std::set<PyObject *> BindingManager::getAllPyObjects()
void BindingManager::visitAllPyObjects(ObjectVisitor visitor, void *data)
{
WrapperMap copy = m_d->wrapperMapper;
- for (auto it = copy.begin(); it != copy.end(); ++it) {
- if (hasWrapper(it->first))
- visitor(it->second, data);
+ for (const auto &p : copy) {
+ if (hasWrapper(p.first))
+ visitor(p.second, data);
}
}
diff --git a/sources/shiboken6/libshiboken/pep384impl.cpp b/sources/shiboken6/libshiboken/pep384impl.cpp
index e3b8904a5..1e96a12eb 100644
--- a/sources/shiboken6/libshiboken/pep384impl.cpp
+++ b/sources/shiboken6/libshiboken/pep384impl.cpp
@@ -866,13 +866,13 @@ _Pep_PrivateMangle(PyObject *self, PyObject *name)
wchar_t bigbuf[big_stack];
wchar_t *resbuf = amount <= big_stack ? bigbuf : (wchar_t *)malloc(sizeof(wchar_t) * amount);
if (!resbuf)
- return 0;
+ return nullptr;
/* ident = "_" + priv[ipriv:] + ident # i.e. 1+plen+nlen bytes */
resbuf[0] = '_';
if (PyUnicode_AsWideChar(privateobj, resbuf + 1, ipriv + plen) < 0)
- return 0;
+ return nullptr;
if (PyUnicode_AsWideChar(name, resbuf + ipriv + plen + 1, nlen) < 0)
- return 0;
+ return nullptr;
PyObject *result = PyUnicode_FromWideChar(resbuf + ipriv, 1 + plen + nlen);
if (amount > big_stack)
free(resbuf);
diff --git a/sources/shiboken6/libshiboken/sbkconverter_p.h b/sources/shiboken6/libshiboken/sbkconverter_p.h
index dfce57755..6664670b3 100644
--- a/sources/shiboken6/libshiboken/sbkconverter_p.h
+++ b/sources/shiboken6/libshiboken/sbkconverter_p.h
@@ -278,7 +278,7 @@ struct Primitive<PY_LONG_LONG> : OnePrimitive<PY_LONG_LONG>
{
PY_LONG_LONG result = PyLong_AsLongLong(pyIn);
if (OverFlowChecker<PY_LONG_LONG>::check(result, pyIn))
- PyErr_SetObject(PyExc_OverflowError, 0);
+ PyErr_SetObject(PyExc_OverflowError, nullptr);
*reinterpret_cast<PY_LONG_LONG * >(cppOut) = result;
}
static PythonToCppFunc isConvertible(PyObject *pyIn)
diff --git a/sources/shiboken6/libshiboken/sbkenum.cpp b/sources/shiboken6/libshiboken/sbkenum.cpp
index 2cc0b935e..51e86829a 100644
--- a/sources/shiboken6/libshiboken/sbkenum.cpp
+++ b/sources/shiboken6/libshiboken/sbkenum.cpp
@@ -462,8 +462,8 @@ int enumIsFlag(PyObject *ob_type)
if (metatype != reinterpret_cast<PyTypeObject *>(PyEnumMeta))
return -1;
auto *mro = reinterpret_cast<PyTypeObject *>(ob_type)->tp_mro;
- Py_ssize_t idx, n = PyTuple_GET_SIZE(mro);
- for (idx = 0; idx < n; idx++) {
+ const Py_ssize_t n = PyTuple_GET_SIZE(mro);
+ for (Py_ssize_t idx = 0; idx < n; ++idx) {
auto *sub_type = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, idx));
if (sub_type == reinterpret_cast<PyTypeObject *>(PyFlag))
return 1;