Fix static analysis issue 24/226324/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 10 Feb 2020 08:21:14 +0000 (17:21 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Mon, 23 Mar 2020 06:07:15 +0000 (15:07 +0900)
Change codes to return result

Change-Id: I1a4e790aa7d0694c6de19192f18ca48e835fa90e
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
(cherry picked from commit 44504f33df2367229c77534baed75aa6b1418747)

src/common/utils/file_logbackend.cc
src/common/utils/file_logbackend.h

index 389cc09..5220f6b 100644 (file)
@@ -37,7 +37,8 @@ void FileLogBackend::WriteLogToFile() {
 
   int size = GetFileSize(file_name_);
   if (size > rotation_size_)
-    Rotate();
+    if (!Rotate())
+      return;
 
   std::ofstream ofs(file_name_.c_str(), std::ios::app);
   ofs << log_stream_->str();
@@ -48,19 +49,24 @@ void FileLogBackend::WriteLogToFile() {
   log_stream_->clear();
 }
 
-void FileLogBackend::Rotate() {
+bool FileLogBackend::Rotate() {
   for (int i = max_rotation_; i > 0; i--) {
     std::string old_log = file_name_ + "." + std::to_string(i);
     // the oldest log will be removed
     if (i == max_rotation_) {
-      std::remove(old_log.c_str());
+      if (std::remove(old_log.c_str()) != 0)
+        return false;
     } else {
       std::string new_log = file_name_ + "." + std::to_string(i + 1);
-      std::rename(old_log.c_str(), new_log.c_str());
+      if (std::rename(old_log.c_str(), new_log.c_str()) != 0)
+        return false;
     }
   }
   std::string new_log = file_name_ + ".1";
-  std::rename(file_name_.c_str(), new_log.c_str());
+  if (std::rename(file_name_.c_str(), new_log.c_str()) != 0)
+    return false;
+
+  return true;
 }
 
 int FileLogBackend::GetFileSize(const std::string& file_name) {
index ce44943..1bfb6ce 100644 (file)
@@ -21,7 +21,7 @@ class FileLogBackend : public ILogBackend {
   void WriteLogToFile();
 
  private:
-  void Rotate();
+  bool Rotate();
   int GetFileSize(const std::string& file_name);
   std::string GetTimeStamp();
   std::string GetPid();