@@ -1844,18 +1844,18 @@ PyCursesWindow_GetStr(PyObject *op, PyObject *args)
18441844 break ;
18451845 case 1 :
18461846 if (!PyArg_ParseTuple (args ,"i;n" , & n ))
1847- return NULL ;
1847+ goto error ;
18481848 if (n < 0 ) {
18491849 PyErr_SetString (PyExc_ValueError , "'n' must be nonnegative" );
1850- return NULL ;
1850+ goto error ;
18511851 }
18521852 Py_BEGIN_ALLOW_THREADS
18531853 rtn = wgetnstr (self -> win , buf , Py_MIN (n , max_buf_size - 1 ));
18541854 Py_END_ALLOW_THREADS
18551855 break ;
18561856 case 2 :
18571857 if (!PyArg_ParseTuple (args ,"ii;y,x" ,& y ,& x ))
1858- return NULL ;
1858+ goto error ;
18591859 Py_BEGIN_ALLOW_THREADS
18601860#ifdef STRICT_SYSV_CURSES
18611861 rtn = wmove (self -> win ,y ,x )== ERR ? ERR : wgetnstr (self -> win , rtn , max_buf_size - 1 );
@@ -1866,10 +1866,10 @@ PyCursesWindow_GetStr(PyObject *op, PyObject *args)
18661866 break ;
18671867 case 3 :
18681868 if (!PyArg_ParseTuple (args ,"iii;y,x,n" , & y , & x , & n ))
1869- return NULL ;
1869+ goto error ;
18701870 if (n < 0 ) {
18711871 PyErr_SetString (PyExc_ValueError , "'n' must be nonnegative" );
1872- return NULL ;
1872+ goto error ;
18731873 }
18741874#ifdef STRICT_SYSV_CURSES
18751875 Py_BEGIN_ALLOW_THREADS
@@ -1884,19 +1884,23 @@ PyCursesWindow_GetStr(PyObject *op, PyObject *args)
18841884 break ;
18851885 default :
18861886 PyErr_SetString (PyExc_TypeError , "getstr requires 0 to 3 arguments" );
1887- return NULL ;
1887+ goto error ;
18881888 }
18891889
18901890 if (rtn == ERR ) {
18911891 Py_DECREF (result );
18921892 return Py_GetConstant (Py_CONSTANT_EMPTY_BYTES );
18931893 }
18941894
1895- if (_PyBytes_Resize (& result , rtn ) < 0 ) {
1895+ if (_PyBytes_Resize (& result , strlen ( buf ) ) < 0 ) {
18961896 return NULL ;
18971897 }
18981898
18991899 return result ;
1900+
1901+ error :
1902+ Py_DECREF (result );
1903+ return NULL ;
19001904}
19011905
19021906/*[clinic input]
@@ -2065,42 +2069,46 @@ PyCursesWindow_InStr(PyObject *op, PyObject *args)
20652069 break ;
20662070 case 1 :
20672071 if (!PyArg_ParseTuple (args ,"i;n" , & n ))
2068- return NULL ;
2072+ goto error ;
20692073 if (n < 0 ) {
20702074 PyErr_SetString (PyExc_ValueError , "'n' must be nonnegative" );
2071- return NULL ;
2075+ goto error ;
20722076 }
20732077 rtn = winnstr (self -> win , buf , Py_MIN (n , max_buf_size - 1 ));
20742078 break ;
20752079 case 2 :
20762080 if (!PyArg_ParseTuple (args ,"ii;y,x" ,& y ,& x ))
2077- return NULL ;
2081+ goto error ;
20782082 rtn = mvwinnstr (self -> win , y , x , buf , max_buf_size - 1 );
20792083 break ;
20802084 case 3 :
20812085 if (!PyArg_ParseTuple (args , "iii;y,x,n" , & y , & x , & n ))
2082- return NULL ;
2086+ goto error ;
20832087 if (n < 0 ) {
20842088 PyErr_SetString (PyExc_ValueError , "'n' must be nonnegative" );
2085- return NULL ;
2089+ goto error ;
20862090 }
20872091 rtn = mvwinnstr (self -> win , y , x , buf , Py_MIN (n , max_buf_size - 1 ));
20882092 break ;
20892093 default :
20902094 PyErr_SetString (PyExc_TypeError , "instr requires 0 or 3 arguments" );
2091- return NULL ;
2095+ goto error ;
20922096 }
20932097
20942098 if (rtn == ERR ) {
20952099 Py_DECREF (result );
20962100 return Py_GetConstant (Py_CONSTANT_EMPTY_BYTES );
20972101 }
20982102
2099- if (_PyBytes_Resize (& result , rtn ) < 0 ) {
2100- return NULL ;
2103+ if (_PyBytes_Resize (& result , strlen ( buf ) ) < 0 ) {
2104+ return NULL ;
21012105 }
21022106
21032107 return result ;
2108+
2109+ error :
2110+ Py_DECREF (result );
2111+ return NULL ;
21042112}
21052113
21062114/*[clinic input]
0 commit comments