!98 fix PerfFile_fuzzer test failed issue

Merge pull request !98 from wenlong_12/master
This commit is contained in:
openharmony_ci 2022-06-23 07:28:19 +00:00 committed by Gitee
commit d448b70c59
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -14,6 +14,7 @@
*/
#include "PerfFile_fuzzer.h"
#include "utilities.h"
namespace OHOS {
using namespace OHOS::Developtools::HiPerf;
@ -63,18 +64,15 @@ public:
static std::unique_ptr<PerfFileReaderFuzzer> Instance(const std::string &fileName,
const uint8_t *data, size_t size)
{
FILE *fp_ = fopen(fileName.c_str(), "rb");
if (fp_ == nullptr) {
return nullptr;
}
std::unique_ptr<FILE, decltype(&fclose)> fp(fp_, fclose);
std::string resolvedPath = CanonicalizeSpecPath(fileName.c_str());
FILE *fp = fopen(resolvedPath.c_str(), "rb");
if (fp == nullptr) {
HLOGE("fail to open file %s", fileName.c_str());
return nullptr;
}
std::unique_ptr<PerfFileReaderFuzzer> reader =
std::make_unique<PerfFileReaderFuzzer>(fileName, fp.get());
std::make_unique<PerfFileReaderFuzzer>(resolvedPath, fp);
reader->dataPtr_ = reinterpret_cast<const char *>(data);
reader->dataSize_ = size;