From 401f9b45a7c84f491eb3d194071bdb941ed212df Mon Sep 17 00:00:00 2001
From: Tobias Knopff <t.knopff@fz-juelich.de>
Date: Tue, 20 Apr 2021 08:43:37 +0200
Subject: [PATCH] Added handling of negative values of signed integers to get
 rid of warning

---
 .../InputOutput/OutputDataReadWriteNicos.cpp   | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/Device/InputOutput/OutputDataReadWriteNicos.cpp b/Device/InputOutput/OutputDataReadWriteNicos.cpp
index 6371b007503..5a787955a9d 100644
--- a/Device/InputOutput/OutputDataReadWriteNicos.cpp
+++ b/Device/InputOutput/OutputDataReadWriteNicos.cpp
@@ -21,8 +21,8 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
     std::string line;
     m_currentLineNr = 0;
 
-    int width = 0;
-    int height = 0;
+    unsigned int width = 0;
+    unsigned int height = 0;
 
     // -- read dimensions
     bool inFileSection = false;
@@ -45,9 +45,9 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
         }
 
         if (StringUtils::startsWith(line, "DataSizeX"))
-            width = readAssignedIntValue(line);
+            width = std::max(readAssignedIntValue(line), 0);
         else if (StringUtils::startsWith(line, "DataSizeY"))
-            height = readAssignedIntValue(line);
+            height = std::max(readAssignedIntValue(line), 0);
 
         if (width != 0 && height != 0)
             break;
@@ -56,9 +56,11 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
     if (!fileSectionFound)
         throw std::runtime_error("Could not find 'File' section.");
     if (width == 0)
-        throw std::runtime_error("Could not find 'DataSizeX' value.");
+        throw std::runtime_error
+            ("Could not find 'DataSizeX' value or value is nonpositive.");
     if (height == 0)
-        throw std::runtime_error("Could not find 'DataSizeY' value.");
+        throw std::runtime_error
+            ("Could not find 'DataSizeY' value or value is nonpositive.");
 
     result->addAxis("x", width, 0.0, width);
     result->addAxis("y", height, 0.0, height);
@@ -66,7 +68,7 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
     // -- read data
     bool inCountSection = false;
     bool countSectionFound = false;
-    int dataRow = 0;
+    unsigned int dataRow = 0;
 
     while (std::getline(input_stream, line)) {
         m_currentLineNr++;
@@ -98,7 +100,7 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
 
         for (unsigned col = 0; col < width; ++col) {
             const size_t global_index =
-                result->toGlobalIndex({col, static_cast<unsigned>(height) - 1
+                result->toGlobalIndex({col, height - 1
                                                 - dataRow}); // y-axis "0" is at bottom => invert y
                                                              // to show first line at top of image
 
-- 
GitLab