@@ -613,13 +613,13 @@ pg_circle_collidelist(pgCircleObject *self, PyObject *arg)
613
613
if (PySequence_FAST_CHECK (arg )) {
614
614
PyObject * * items = PySequence_Fast_ITEMS (arg );
615
615
for (i = 0 ; i < PySequence_Fast_GET_SIZE (arg ); i ++ ) {
616
- colliding = _pg_circle_collideswith (scirc , items [i ]);
617
- if (colliding == 1 ) {
618
- return PyLong_FromSsize_t (i );
619
- }
620
- else if (colliding == -1 ) {
616
+ if ((colliding = _pg_circle_collideswith (scirc , items [i ])) == -1 ) {
617
+ /*invalid shape*/
621
618
return NULL ;
622
619
}
620
+ if (colliding ) {
621
+ return PyLong_FromSsize_t (i );
622
+ }
623
623
}
624
624
return PyLong_FromLong (-1 );
625
625
}
@@ -631,15 +631,16 @@ pg_circle_collidelist(pgCircleObject *self, PyObject *arg)
631
631
return NULL ;
632
632
}
633
633
634
- colliding = _pg_circle_collideswith (scirc , obj );
634
+ if ((colliding = _pg_circle_collideswith (scirc , obj )) == -1 ) {
635
+ /*invalid shape*/
636
+ Py_DECREF (obj );
637
+ return NULL ;
638
+ }
635
639
Py_DECREF (obj );
636
640
637
- if (colliding == 1 ) {
641
+ if (colliding ) {
638
642
return PyLong_FromSsize_t (i );
639
643
}
640
- else if (colliding == -1 ) {
641
- return NULL ;
642
- }
643
644
}
644
645
645
646
return PyLong_FromLong (-1 );
@@ -667,27 +668,28 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg)
667
668
PyObject * * items = PySequence_Fast_ITEMS (arg );
668
669
669
670
for (i = 0 ; i < PySequence_Fast_GET_SIZE (arg ); i ++ ) {
670
- colliding = _pg_circle_collideswith (scirc , items [i ]);
671
-
672
- if (colliding == 1 ) {
673
- PyObject * num = PyLong_FromSsize_t (i );
674
- if (!num ) {
675
- Py_DECREF (ret );
676
- return NULL ;
677
- }
678
-
679
- if (PyList_Append (ret , num )) {
680
- Py_DECREF (num );
681
- Py_DECREF (ret );
682
- return NULL ;
683
- }
684
- Py_DECREF (num );
671
+ if ((colliding = _pg_circle_collideswith (scirc , items [i ])) == -1 ) {
672
+ /*invalid shape*/
673
+ Py_DECREF (ret );
674
+ return NULL ;
685
675
}
686
- /*invalid shape*/
687
- else if (colliding == -1 ) {
676
+
677
+ if (!colliding ) {
678
+ continue ;
679
+ }
680
+
681
+ PyObject * num = PyLong_FromSsize_t (i );
682
+ if (!num ) {
688
683
Py_DECREF (ret );
689
684
return NULL ;
690
685
}
686
+
687
+ if (PyList_Append (ret , num )) {
688
+ Py_DECREF (num );
689
+ Py_DECREF (ret );
690
+ return NULL ;
691
+ }
692
+ Py_DECREF (num );
691
693
}
692
694
693
695
return ret ;
@@ -701,28 +703,30 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg)
701
703
return NULL ;
702
704
}
703
705
704
- colliding = _pg_circle_collideswith (scirc , obj );
706
+ if ((colliding = _pg_circle_collideswith (scirc , obj )) == -1 ) {
707
+ /*invalid shape*/
708
+ Py_DECREF (ret );
709
+ Py_DECREF (obj );
710
+ return NULL ;
711
+ }
705
712
Py_DECREF (obj );
706
713
707
- if (colliding == 1 ) {
708
- PyObject * num = PyLong_FromSsize_t (i );
709
- if (!num ) {
710
- Py_DECREF (ret );
711
- return NULL ;
712
- }
714
+ if (!colliding ) {
715
+ continue ;
716
+ }
713
717
714
- if (PyList_Append (ret , num )) {
715
- Py_DECREF (num );
716
- Py_DECREF (ret );
717
- return NULL ;
718
- }
719
- Py_DECREF (num );
718
+ PyObject * num = PyLong_FromSsize_t (i );
719
+ if (!num ) {
720
+ Py_DECREF (ret );
721
+ return NULL ;
720
722
}
721
- /*invalid shape*/
722
- else if (colliding == -1 ) {
723
+
724
+ if (PyList_Append (ret , num )) {
725
+ Py_DECREF (num );
723
726
Py_DECREF (ret );
724
727
return NULL ;
725
728
}
729
+ Py_DECREF (num );
726
730
}
727
731
728
732
return ret ;
0 commit comments