Fix fread unused_result warning (#92)
* Fix fread unused_result warning
Check the read of the source binary succeeded, and if not generate an
exception and let the user know.
Fixes #91
* Use fail() to signal file read error
diff --git a/main.cpp b/main.cpp
index 1f38c24..b823117 100644
--- a/main.cpp
+++ b/main.cpp
@@ -866,7 +866,10 @@
this_size = std::min(size, result.first.max_offset - result.first.offset);
assert(this_size);
fseek(file, result.second + result.first.offset, SEEK_SET);
- fread(buffer, this_size, 1, file);
+ auto read_bytes = fread(buffer, 1, this_size, file);
+ if (this_size != read_bytes) {
+ fail(ERROR_READ_FAILED, "Source file read error");
+ }
} catch (not_mapped_exception &e) {
if (zero_fill) {
// address is not in a range, so fill up to next range with zeros