phrocker commented on a change in pull request #472: MINIFICPP-710 - Fix errors 
in Property StringToInt conversion
URL: https://github.com/apache/nifi-minifi-cpp/pull/472#discussion_r246971581
 
 

 ##########
 File path: libminifi/include/core/TypedValues.h
 ##########
 @@ -141,6 +141,47 @@ class TimePeriodValue : public TransformableValue, public 
state::response::UInt6
  * format <numeric> <byte size>.
  */
 class DataSizeValue : public TransformableValue, public 
state::response::UInt64Value {
+private:
+
+  //Signed
+  template<typename T, typename std::enable_if<std::is_signed<T>::value, 
T>::type* = nullptr>
+  static bool AssignIfFits(int64_t base, uint64_t mult, T& output) {
+    int64_t val = base * mult;
+    if(val >= std::numeric_limits<T>::min() && val <= 
std::numeric_limits<T>::max()) {
+      output = val;
+      return true;
+    }
+    return false;
+  }
+
+  //Unsigned
+  template<typename T, typename std::enable_if<!std::is_signed<T>::value, 
T>::type* = nullptr>
+  static bool AssignIfFits(uint64_t base, uint64_t mult, T& output) {
+    uint64_t val = base * mult;
+    if(val <= std::numeric_limits<T>::max()) {
+      output = val;
+      return true;
+    }
+    return false;
+  }
+
+  //Signed
+  template<typename T, typename std::enable_if<std::is_signed<T>::value, 
T>::type* = nullptr>
+  static bool StringToNum(const char* str_begin, char **str_end, T& output) {
+    int64_t val = std::strtoll(str_begin, str_end, 0);
+    return AssignIfFits<T>(val, 1, output);
+  }
+
+  //Unsigned
+  template<typename T, typename std::enable_if<!std::is_signed<T>::value, 
T>::type* = nullptr>
+  static bool StringToNum(const char* str_begin, char **str_end, T& output) {
+    if(str_begin[0] == '-') {
 
 Review comment:
   can't assume that it's zero, and that it's non-empty

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to