Skip to content

Commit

Permalink
Fix QgsPoint ctor with invalid arguments
Browse files Browse the repository at this point in the history
Fixes #34557
  • Loading branch information
elpaso committed Feb 20, 2020
1 parent b840ad7 commit 8cbb23c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions python/core/auto_generated/geometry/qgspoint.sip.in
Expand Up @@ -56,7 +56,7 @@ based on the following rules:
if ( sipCanConvertToType( a0, sipType_QgsPointXY, SIP_NOT_NONE ) && a1 == Py_None && a2 == Py_None && a3 == Py_None && a4 == Py_None )
{
int state;
int sipIsErr = 0;
sipIsErr = 0;

QgsPointXY *p = reinterpret_cast<QgsPointXY *>( sipConvertToType( a0, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
if ( sipIsErr )
Expand All @@ -71,7 +71,7 @@ based on the following rules:
else if ( sipCanConvertToType( a0, sipType_QPointF, SIP_NOT_NONE ) && a1 == Py_None && a2 == Py_None && a3 == Py_None && a4 == Py_None )
{
int state;
int sipIsErr = 0;
sipIsErr = 0;

QPointF *p = reinterpret_cast<QPointF *>( sipConvertToType( a0, sipType_QPointF, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
if ( sipIsErr )
Expand All @@ -97,6 +97,11 @@ based on the following rules:
QgsWkbTypes::Type wkbType = a4 == Py_None ? QgsWkbTypes::Unknown : static_cast<QgsWkbTypes::Type>( sipConvertToEnum( a4, sipType_QgsWkbTypes_Type ) );
sipCpp = new sipQgsPoint( QgsPoint( x, y, z, m, wkbType ) );
}
else // Invalid ctor arguments
{
PyErr_SetString( PyExc_TypeError, QStringLiteral( "Invalid type in constructor arguments." ).toUtf8().constData() );
sipIsErr = 1;
}
%End


Expand Down
9 changes: 7 additions & 2 deletions src/core/geometry/qgspoint.h
Expand Up @@ -78,7 +78,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
if ( sipCanConvertToType( a0, sipType_QgsPointXY, SIP_NOT_NONE ) && a1 == Py_None && a2 == Py_None && a3 == Py_None && a4 == Py_None )
{
int state;
int sipIsErr = 0;
sipIsErr = 0;

QgsPointXY *p = reinterpret_cast<QgsPointXY *>( sipConvertToType( a0, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
if ( sipIsErr )
Expand All @@ -93,7 +93,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
else if ( sipCanConvertToType( a0, sipType_QPointF, SIP_NOT_NONE ) && a1 == Py_None && a2 == Py_None && a3 == Py_None && a4 == Py_None )
{
int state;
int sipIsErr = 0;
sipIsErr = 0;

QPointF *p = reinterpret_cast<QPointF *>( sipConvertToType( a0, sipType_QPointF, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
if ( sipIsErr )
Expand All @@ -119,6 +119,11 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
QgsWkbTypes::Type wkbType = a4 == Py_None ? QgsWkbTypes::Unknown : static_cast<QgsWkbTypes::Type>( sipConvertToEnum( a4, sipType_QgsWkbTypes_Type ) );
sipCpp = new sipQgsPoint( QgsPoint( x, y, z, m, wkbType ) );
}
else // Invalid ctor arguments
{
PyErr_SetString( PyExc_TypeError, QStringLiteral( "Invalid type in constructor arguments." ).toUtf8().constData() );
sipIsErr = 1;
}
% End
#endif

Expand Down
13 changes: 13 additions & 0 deletions tests/src/python/test_qgspoint.py
Expand Up @@ -87,5 +87,18 @@ def test_issue_32443(self):
assert p.wkbType() == QgsWkbTypes.PointZM and p.x() == 1 and p.y() == 2 and p.z() == 3 and p.m() == 4


class TestQgsPoint(unittest.TestCase):

def testInvalidConstructorArguments(self):
"""Test GH #34557"""

with self.assertRaises(TypeError):
point_0 = QgsPoint('a string')

with self.assertRaises(TypeError):
point_a = QgsPoint(10, 20)
point_b = QgsPoint(point_a)


if __name__ == '__main__':
unittest.main()

0 comments on commit 8cbb23c

Please sign in to comment.