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

Skip to content

Commit a56c883

Browse files
committed
Check the return value of fwrite (and eliminate gcc 4.x warnings)
svn path=/trunk/matplotlib/; revision=5097
1 parent 0853823 commit a56c883

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/_backend_agg.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,16 @@ RendererAgg::write_rgba(const Py::Tuple& args) {
13001300
const char *file_name = fileName.c_str();
13011301
if ((fp = fopen(file_name, "wb")) == NULL)
13021302
throw Py::RuntimeError( Printf("Could not open file %s", file_name).str() );
1303-
fwrite(pixBuffer, 1, NUMBYTES, fp);
1303+
if (fwrite(pixBuffer, 1, NUMBYTES, fp) != NUMBYTES) {
1304+
fclose(fp);
1305+
throw Py::RuntimeError( Printf("Error writing to file %s", file_name).str() );
1306+
}
13041307
close_file = true;
1305-
fclose(fp);
13061308
} else if (PyFile_CheckExact(py_fileobj.ptr())) {
13071309
fp = PyFile_AsFile(py_fileobj.ptr());
1308-
fwrite(pixBuffer, 1, NUMBYTES, fp);
1310+
if (fwrite(pixBuffer, 1, NUMBYTES, fp) != NUMBYTES) {
1311+
throw Py::RuntimeError( "Error writing to file" );
1312+
}
13091313
} else {
13101314
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(), "write");
13111315
if (!(write_method && PyCallable_Check(write_method))) {

0 commit comments

Comments
 (0)