From d0e98eb3f1e6bcd76c63da672507caf9a743af07 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 1 Apr 2011 23:54:58 +0000 Subject: [PATCH] handle return of fread --- agg/src/agg_gsv_text.cpp | 2 +- src/png_reader.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/agg/src/agg_gsv_text.cpp b/agg/src/agg_gsv_text.cpp index b7ed09952..fb4be5a94 100644 --- a/agg/src/agg_gsv_text.cpp +++ b/agg/src/agg_gsv_text.cpp @@ -555,7 +555,7 @@ namespace agg if(len > 0) { m_loaded_font.resize(len); - if (fread(&m_loaded_font[0], 1, len, fd) == 1) + if (fread(&m_loaded_font[0], 1, len, fd) == len) { m_font = &m_loaded_font[0]; } diff --git a/src/png_reader.cpp b/src/png_reader.cpp index 7664989ee..3dfaab3ea 100644 --- a/src/png_reader.cpp +++ b/src/png_reader.cpp @@ -97,7 +97,11 @@ void png_reader::init() if (!fp) throw image_reader_exception("cannot open image file "+fileName_); png_byte header[8]; memset(header,0,8); - fread(header,1,8,fp); + if ( fread(header,1,8,fp) != 8) + { + fclose(fp); + throw image_reader_exception("Could not read " + fileName_); + } int is_png=!png_sig_cmp(header,0,8); if (!is_png) {