arpadboda 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_r247029323
##########
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);
Review comment:
Just to reuse that code. The goal here was to make sure that the value just
read fits target in case that's smaller than 64 bits.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services