incorrect check for fwrite fail (#541)

This commit is contained in:
Dhanya Thattil 2022-08-31 15:53:24 +02:00 committed by GitHub
parent d73d8994c0
commit 4913c9c0b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 9 deletions

View File

@ -103,13 +103,10 @@ void BinaryDataFile::WriteToFile(char *imageData, sls_receiver_header &header,
} }
// if write error // if write error
if (ret != imageSize + sizeof(sls_receiver_header)) { if (ret != 1) {
throw RuntimeError( throw RuntimeError(std::to_string(index) +
std::to_string(index) +
" : Write to file failed for image number " + " : Write to file failed for image number " +
std::to_string(currentFrameNumber) + ". Wrote " + std::to_string(currentFrameNumber));
std::to_string(ret) + " bytes instead of " +
std::to_string(imageSize + sizeof(sls_receiver_header)));
} }
} }

View File

@ -32,8 +32,7 @@ std::string CreateMasterBinaryFile(const std::string &filePath,
rapidjson::StringBuffer s; rapidjson::StringBuffer s;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s); rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s);
attr->GetBinaryAttributes(&writer); attr->GetBinaryAttributes(&writer);
if (fwrite(s.GetString(), 1, strlen(s.GetString()), fd) != if (fwrite(s.GetString(), strlen(s.GetString()), 1, fd) != 1) {
strlen(s.GetString())) {
throw RuntimeError( throw RuntimeError(
"Master binary file incorrect number of bytes written to file"); "Master binary file incorrect number of bytes written to file");
} }