Fix static analyzer issues 50/122550/1
authorSangyoon Jang <s89.jang@samsung.com>
Mon, 3 Apr 2017 03:48:54 +0000 (12:48 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Mon, 3 Apr 2017 03:48:54 +0000 (12:48 +0900)
Change-Id: I0c3cfacfd7e1a2a922b6f80ba5738e7e5f9cdc2b
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/pkg_initdb/pkg_initdb.cc
src/pkg_recovery/pkg_recovery_helper.cc

index d9cfbed..8f50bab 100644 (file)
@@ -2,6 +2,7 @@
 // Use of this source code is governed by an apache-2.0 license that can be
 // found in the LICENSE file.
 
+#include <boost/exception/diagnostic_information.hpp>
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/path.hpp>
 #include <boost/program_options.hpp>
@@ -155,15 +156,9 @@ int main(int argc, char *argv[]) {
       initial = true;
     bpo::notify(opt_map);
     uid = opt_map["uid"].as<int>();
-  } catch (const bpo::error& error) {
-    std::cerr << error.what() << std::endl;
-    return -1;
-  } catch (const boost::bad_any_cast& error) {
-    std::cerr << error.what() << std::endl;
-    return -1;
-  } catch (const boost::bad_lexical_cast& error) {
-    std::cerr << error.what() << std::endl;
-    return -1;
+  } catch (const boost::exception& error) {
+    std::cerr << "Exception occured: " << boost::diagnostic_information(error)
+              << std::endl;
   }
 
   RemoveOldDatabases(uid);
index e12c573..cd7e513 100644 (file)
@@ -85,13 +85,8 @@ bool DoRecoveryProcess(uid_t uid) {
   for (bf::directory_iterator iter(recovery_dir);
       iter != bf::directory_iterator();
       ++iter) {
-    try {
-      if (bf::is_directory(iter->path()))
-        continue;
-    } catch (const bf::filesystem_error& e) {
-      LOG(ERROR) << "Failed to get is_directory result: " << e.what();
+    if (bf::is_directory(iter->path()))
       continue;
-    }
     std::string file = iter->path().filename().string();
     std::regex recovery_regex(kRecoveryFilePattern);
     std::smatch match;
@@ -110,8 +105,13 @@ bool DoRecoveryProcess(uid_t uid) {
 
 int main() {
   uid_t uid = getuid();
-  DoRecoveryProcess(uid);
-  if (ci::IsAdminUser(uid))
-    DoRecoveryProcess(kGlobalUserUid);
+  try {
+    DoRecoveryProcess(uid);
+    if (ci::IsAdminUser(uid))
+      DoRecoveryProcess(kGlobalUserUid);
+  } catch (const bf::filesystem_error& e) {
+    LOG(ERROR) << "Exception occurred: " << e.what();
+    return -1;
+  }
   return 0;
 }