From 6c33493f460d5e6dd04ac3448645e658a87aa04d Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Fri, 30 Jun 2017 15:34:04 +0200
Subject: [PATCH] [App] DE: Fix warning. Avoid undefined behaviour.

Use static_cast to unsigned integer because count is non-negative.
Check if iterator is not pointint to the list's end before access.
---
 Applications/DataExplorer/DataView/StationTreeModel.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Applications/DataExplorer/DataView/StationTreeModel.cpp b/Applications/DataExplorer/DataView/StationTreeModel.cpp
index 70b7fa9defa..3939130824b 100644
--- a/Applications/DataExplorer/DataView/StationTreeModel.cpp
+++ b/Applications/DataExplorer/DataView/StationTreeModel.cpp
@@ -100,7 +100,7 @@ vtkPolyDataAlgorithm* StationTreeModel::vtkSource(const std::string &name) const
 }
 
 void StationTreeModel::setNameForItem(const std::string& stn_vec_name,
-                                      std::size_t id,
+                                      std::size_t const id,
                                       std::string const& item_name)
 {
     auto const stn_list = find_if(
@@ -108,7 +108,8 @@ void StationTreeModel::setNameForItem(const std::string& stn_vec_name,
             return (stn_vec_name == item->data(0).toString().toStdString());
         });
 
-    if (id >=  (*stn_list)->childCount())
+    if (stn_list == _lists.end() ||
+        id >= static_cast<std::size_t>((*stn_list)->childCount()))
         return;
     TreeItem *const item = (*stn_list)->child(id);
     item->setData(0, QString::fromStdString(item_name));
-- 
GitLab