From d8c00da9d93587ce3a2a5c721bbac2794bea07e2 Mon Sep 17 00:00:00 2001 From: Jonathan Nguyen Date: Thu, 20 Feb 2020 12:49:01 -0800 Subject: [PATCH] Make findTrainInfoFileNameLocked return a string instead of a char*. Test: atest GtsStatsdHostTestCases on hwasan Change-Id: I51a3a7101588001ccb5479ae599a6b52d3a56566 --- cmds/statsd/src/storage/StorageManager.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmds/statsd/src/storage/StorageManager.cpp b/cmds/statsd/src/storage/StorageManager.cpp index 4899b4a5247c4..dcfdfe3aae531 100644 --- a/cmds/statsd/src/storage/StorageManager.cpp +++ b/cmds/statsd/src/storage/StorageManager.cpp @@ -75,11 +75,11 @@ string StorageManager::getDataHistoryFileName(long wallClockSec, int uid, int64_ (long long)id); } -static const char* findTrainInfoFileNameLocked(const string& trainName) { +static string findTrainInfoFileNameLocked(const string& trainName) { unique_ptr dir(opendir(TRAIN_INFO_DIR), closedir); if (dir == NULL) { VLOG("Path %s does not exist", TRAIN_INFO_DIR); - return nullptr; + return ""; } dirent* de; while ((de = readdir(dir.get()))) { @@ -90,12 +90,12 @@ static const char* findTrainInfoFileNameLocked(const string& trainName) { if (fileNameLength >= trainName.length()) { if (0 == strncmp(fileName + fileNameLength - trainName.length(), trainName.c_str(), trainName.length())) { - return fileName; + return string(fileName); } } } - return nullptr; + return ""; } // Returns array of int64_t which contains timestamp in seconds, uid, @@ -267,13 +267,13 @@ bool StorageManager::readTrainInfo(const std::string& trainName, InstallTrainInf bool StorageManager::readTrainInfoLocked(const std::string& trainName, InstallTrainInfo& trainInfo) { trimToFit(TRAIN_INFO_DIR, /*parseTimestampOnly=*/ true); - const char* fileName = findTrainInfoFileNameLocked(trainName); - if (fileName == nullptr) { + string fileName = findTrainInfoFileNameLocked(trainName); + if (fileName.empty()) { return false; } - int fd = open(StringPrintf("%s/%s", TRAIN_INFO_DIR, fileName).c_str(), O_RDONLY | O_CLOEXEC); + int fd = open(StringPrintf("%s/%s", TRAIN_INFO_DIR, fileName.c_str()).c_str(), O_RDONLY | O_CLOEXEC); if (fd == -1) { - VLOG("Failed to open %s", fileName); + VLOG("Failed to open %s", fileName.c_str()); return false; }