Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e1b8fa

Browse files
committed
- Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2.
1 parent 1ff110d commit 7e1b8fa

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Core and Builtins
1919
- Issue #4367: Python would segfault during compiling when the unicodedata
2020
module couldn't be imported and \N escapes were present.
2121

22+
- Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2.
23+
2224
Library
2325
-------
2426

Modules/_cursesmodule.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
18571857
int fd;
18581858
FILE *fp;
18591859
PyObject *data;
1860+
size_t datalen;
18601861
WINDOW *win;
18611862

18621863
PyCursesInitialised
@@ -1886,7 +1887,13 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
18861887
remove(fn);
18871888
return NULL;
18881889
}
1889-
fwrite(PyBytes_AS_STRING(data), 1, PyBytes_GET_SIZE(data), fp);
1890+
datalen = PyBytes_GET_SIZE(data);
1891+
if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
1892+
Py_DECREF(data);
1893+
fclose(fp);
1894+
remove(fn);
1895+
return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
1896+
}
18901897
Py_DECREF(data);
18911898
fseek(fp, 0, 0);
18921899
win = getwin(fp);

0 commit comments

Comments
 (0)