Fix static analysis issues 31/290331/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 23 Mar 2023 07:07:41 +0000 (16:07 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Thu, 23 Mar 2023 07:33:56 +0000 (16:33 +0900)
Change-Id: I42df724554cfdc3613b8793774fb0892aed145b9
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/manifest_parser/manifest_parser_impl.cc

index eafddd399eb77e704295cf74d5289db49036554e..9d62c1126d385b5c63f59efe440cb2cbb7b21c1e 100644 (file)
@@ -75,7 +75,7 @@ bool ManifestParserImpl::ParseManifest(const bf::path& manifest_path,
 
 bool ManifestParserImpl::ValidateAppManifest(std::string* error) {
   const ManifestHandlerMap& handlers = registry_->handlers();
-  for (auto p : handlers) {
+  for (const auto& p : handlers) {
     auto handler = p.second;
     if (manifest_data_.find(p.first) != manifest_data_.end() &&
         !handler->Validate(*GetManifestData(handler->Key()).get(),
@@ -99,14 +99,21 @@ bool ManifestParserImpl::ParseAppManifest(std::string* error) {
   const ManifestHandlerMap& handlers = registry_->handlers();
   const ManifestHandlerOrderMap& order_map =
       registry_->get_manifest_handlers_order_map();
-  for (auto p : handlers) {
+  for (const auto& p : handlers) {
     auto handler = p.second;
     if (manifest_->HasPath(p.first) ||
         handler->AlwaysParseForKey()) {
-      handlers_by_order[order_map.find(handler)->second] = handler;
+      const auto& it = order_map.find(handler);
+      if (it != order_map.end()) {
+        handlers_by_order[it->second] = handler;
+      } else {
+        *error = std::string("'") + handler->Key() +
+            "'' does not exist in handlers_by_order map";
+        return false;
+      }
     }
   }
-  for (auto handler : handlers_by_order) {
+  for (const auto& handler : handlers_by_order) {
     std::shared_ptr<ManifestData> output;
     if (handler.second->Parse(*manifest_.get(), &output, error)) {
       if (output)
@@ -164,5 +171,3 @@ void ManifestParserImpl::EraseManifestData(const std::string& key) {
 }
 
 }  // namespace parser
-
-