@@ -790,25 +790,20 @@ np_float_complex(_structmodulestate *state, char *p, PyObject *v,
790790 const formatdef * f )
791791{
792792 Py_complex c = PyComplex_AsCComplex (v );
793+ char tmp [8 ];
793794
794795 if (c .real == -1 && PyErr_Occurred ()) {
795796 PyErr_SetString (state -> StructError ,
796797 "required argument is not a complex" );
797798 return -1 ;
798799 }
799-
800- char tmp [8 ];
801- int ret = PyFloat_Pack4 (c .real , tmp , PY_LITTLE_ENDIAN );
802-
803- if (ret ) {
804- return ret ;
805- }
806- ret = PyFloat_Pack4 (c .imag , tmp + 4 , PY_LITTLE_ENDIAN );
807- if (ret ) {
808- return ret ;
800+ if (PyFloat_Pack4 (c .real , tmp , PY_LITTLE_ENDIAN )
801+ || PyFloat_Pack4 (c .imag , tmp + 4 , PY_LITTLE_ENDIAN ))
802+ {
803+ return -1 ;
809804 }
810805 memcpy (p , tmp , 8 );
811- return ret ;
806+ return 0 ;
812807}
813808
814809static int
@@ -1142,15 +1137,20 @@ static int
11421137bp_float_complex (_structmodulestate * state , char * p , PyObject * v , const formatdef * f )
11431138{
11441139 Py_complex x = PyComplex_AsCComplex (v );
1140+ char tmp [8 ];
1141+
11451142 if (x .real == -1 && PyErr_Occurred ()) {
11461143 PyErr_SetString (state -> StructError ,
11471144 "required argument is not a complex" );
11481145 return -1 ;
11491146 }
1150- if (PyFloat_Pack4 (x .real , p , 0 )) {
1147+ if (PyFloat_Pack4 (x .real , tmp , 0 )
1148+ || PyFloat_Pack4 (x .imag , tmp + 4 , 0 ))
1149+ {
11511150 return -1 ;
11521151 }
1153- return PyFloat_Pack4 (x .imag , p + 4 , 0 );
1152+ memcpy (p , tmp , 8 );
1153+ return 0 ;
11541154}
11551155
11561156static int
@@ -1468,16 +1468,20 @@ static int
14681468lp_float_complex (_structmodulestate * state , char * p , PyObject * v , const formatdef * f )
14691469{
14701470 Py_complex x = PyComplex_AsCComplex (v );
1471+ char tmp [8 ];
1472+
14711473 if (x .real == -1 && PyErr_Occurred ()) {
14721474 PyErr_SetString (state -> StructError ,
14731475 "required argument is not a complex" );
14741476 return -1 ;
14751477 }
1476- if (PyFloat_Pack4 (x .real , p , 1 )) {
1478+ if (PyFloat_Pack4 (x .real , tmp , 1 )
1479+ || PyFloat_Pack4 (x .imag , tmp + 4 , 1 ))
1480+ {
14771481 return -1 ;
14781482 }
1479- return PyFloat_Pack4 ( x . imag , p + 4 , 1 );
1480-
1483+ memcpy ( p , tmp , 8 );
1484+ return 0 ;
14811485}
14821486
14831487static int
0 commit comments