summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-01-24 22:21:02 +0000
committerCarl Hetherington <cth@carlh.net>2019-01-24 22:21:02 +0000
commitd1f2e0128c6f5daa01770b0989c66285f1284985 (patch)
tree617ff136e4dad531a65517d5fd1cfc6503fea888 /src
parent1b9ef11a84b854424267161454a7983f9130c4ea (diff)
Check return value of fread in File::File.
Diffstat (limited to 'src')
-rw-r--r--src/file.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/file.cc b/src/file.cc
index 6fe4b299..ce7a4c5e 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -38,6 +38,7 @@
#include "file.h"
#include "util.h"
#include "dcp_assert.h"
+#include "compose.hpp"
#include <stdio.h>
using namespace dcp;
@@ -51,7 +52,16 @@ File::File (boost::filesystem::path file)
_data = new uint8_t[_size];
FILE* f = dcp::fopen_boost (file, "rb");
DCP_ASSERT (f);
- fread (_data, 1, _size, f);
+ int const N = fread (_data, 1, _size, f);
+ if (N != _size) {
+ if (ferror(f)) {
+ fclose (f);
+ throw FileError (String::compose("fread error %1", errno), file, errno);
+ } else {
+ fclose (f);
+ throw FileError ("unexpected short read", file, -1);
+ }
+ }
fclose (f);
}