Adding code to see if it improves crash on computeHash.
Also add a test case to verify behaviour on empty files is correct. Sentry-Id: FLIGHTGEAR-AY2
This commit is contained in:
@@ -82,7 +82,9 @@ std::string SGFile::computeHash()
|
|||||||
[](char* p) { free(p); }};
|
[](char* p) { free(p); }};
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
SG_LOG(SG_IO, SG_ALERT, "Failed to malloc buffer for SHA1 check");
|
// @TODO report out of memory error
|
||||||
|
SG_LOG(SG_IO, SG_ALERT, "Failed to malloc buffer for SHA1 check:" << file_name);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t readLen;
|
size_t readLen;
|
||||||
|
|||||||
@@ -901,6 +901,27 @@ void testPersistentSocketFailure(HTTP::Client *cl) {
|
|||||||
verifyRequestCount("dirD/subdirDB/fileDBA", 1);
|
verifyRequestCount("dirD/subdirDB/fileDBA", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testHashOnEmptyFile()
|
||||||
|
{
|
||||||
|
std::unique_ptr<HTTPRepository> repo;
|
||||||
|
SGPath p(simgear::Dir::current().path());
|
||||||
|
p.append("sgfile_compute_hash");
|
||||||
|
simgear::Dir pd(p);
|
||||||
|
if (pd.exists()) {
|
||||||
|
pd.removeChildren();
|
||||||
|
} else {
|
||||||
|
pd.create(0700);
|
||||||
|
}
|
||||||
|
|
||||||
|
SGPath fPath = p / "test_empty_file";
|
||||||
|
|
||||||
|
SGFile file(fPath);
|
||||||
|
file.open(SG_IO_OUT);
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
const auto hash = file.computeHash();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
sglog().setLogLevels( SG_ALL, SG_INFO );
|
sglog().setLogLevels( SG_ALL, SG_INFO );
|
||||||
@@ -951,6 +972,8 @@ int main(int argc, char* argv[])
|
|||||||
testRetryAfterSocketFailure(&cl);
|
testRetryAfterSocketFailure(&cl);
|
||||||
testPersistentSocketFailure(&cl);
|
testPersistentSocketFailure(&cl);
|
||||||
|
|
||||||
|
testHashOnEmptyFile();
|
||||||
|
|
||||||
std::cout << "all tests passed ok" << std::endl;
|
std::cout << "all tests passed ok" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user