1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-12 21:31:33 +00:00

Added check in SDL main that the expected number of bytes is read.

This commit is contained in:
Thomas Harte 2017-11-12 16:26:42 -05:00
parent 61f2191c86
commit 2e025d85eb

View File

@ -183,10 +183,10 @@ int main(int argc, char *argv[]) {
std::vector<std::unique_ptr<std::vector<uint8_t>>> results; std::vector<std::unique_ptr<std::vector<uint8_t>>> results;
for(auto &name: names) { for(auto &name: names) {
std::string local_path = "/usr/local/share/CLK/" + machine + "/" + name; std::string local_path = "/usr/local/share/CLK/" + machine + "/" + name;
FILE *file = fopen(local_path.c_str(), "r"); FILE *file = std::fopen(local_path.c_str(), "rb");
if(!file) { if(!file) {
std::string path = "/usr/share/CLK/" + machine + "/" + name; std::string path = "/usr/share/CLK/" + machine + "/" + name;
file = fopen(path.c_str(), "r"); file = std::fopen(path.c_str(), "rb");
} }
if(!file) { if(!file) {
@ -196,13 +196,16 @@ int main(int argc, char *argv[]) {
std::unique_ptr<std::vector<uint8_t>> data(new std::vector<uint8_t>); std::unique_ptr<std::vector<uint8_t>> data(new std::vector<uint8_t>);
fseek(file, 0, SEEK_END); std::fseek(file, 0, SEEK_END);
data->resize(ftell(file)); data->resize(std::ftell(file));
fseek(file, 0, SEEK_SET); std::fseek(file, 0, SEEK_SET);
fread(data->data(), 1, data->size(), file); std::size_t read = fread(data->data(), 1, data->size(), file);
fclose(file); std::fclose(file);
if(read == data->size())
results.emplace_back(std::move(data)); results.emplace_back(std::move(data));
else
results.emplace_back(nullptr);
} }
return results; return results;