]> granicus.if.org Git - python/commitdiff
- Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2.
authorMatthias Klose <doko@ubuntu.com>
Wed, 26 Nov 2008 17:22:04 +0000 (17:22 +0000)
committerMatthias Klose <doko@ubuntu.com>
Wed, 26 Nov 2008 17:22:04 +0000 (17:22 +0000)
Misc/NEWS
Modules/_cursesmodule.c

index 091ef43eb0fa19ee18bc2fac42c14a9e935008dc..6145654c064a68db23f79bedbbd6241b0f7e63b7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,8 @@ Core and Builtins
 - Issue #4367: Python would segfault during compiling when the unicodedata
   module couldn't be imported and \N escapes were present.
 
+- Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2.
+
 Library
 -------
 
index 4f99da5af0f8ea0859251eebfa057333875696bb..3764f482af7cbdaa7f0e724d26e8f3ccad8db768 100644 (file)
@@ -1857,6 +1857,7 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
   int fd;
   FILE *fp;
   PyObject *data;
+  size_t datalen;
   WINDOW *win;
 
   PyCursesInitialised
@@ -1886,7 +1887,13 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
     remove(fn);
     return NULL;
   }
-  fwrite(PyBytes_AS_STRING(data), 1, PyBytes_GET_SIZE(data), fp);
+  datalen = PyBytes_GET_SIZE(data);
+  if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
+    Py_DECREF(data);
+    fclose(fp);
+    remove(fn);
+    return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
+  }
   Py_DECREF(data);
   fseek(fp, 0, 0);
   win = getwin(fp);