From a7c3fd185aea31368434368d843d75c852389eed Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 13 Aug 2020 21:02:14 -0400 Subject: [PATCH] fix issue with uninitialized variables in parameter object --- src/ParameterObject.cpp | 60 ++++++++++++++++++++++++----------------- src/ParameterObject.h | 7 +++++ 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/ParameterObject.cpp b/src/ParameterObject.cpp index 462929a..b6aec85 100644 --- a/src/ParameterObject.cpp +++ b/src/ParameterObject.cpp @@ -40,29 +40,36 @@ namespace eipScanner { : ParameterObject(id, fullAttributes, si, std::make_shared()) { } - ParameterObject::ParameterObject(cip::CipUint instanceId, bool fullAttributes, size_t typeSize) - : BaseObject(CLASS_ID, instanceId) - , _hasFullAttributes(fullAttributes) - , _value(typeSize) - , _maxValue(typeSize) - , _minValue(typeSize) - , _defaultValue(typeSize) - , _isScalable(false) - , _isReadOnly(false) - , _scalingMultiplier(1) - , _scalingDivisor(1) - , _scalingBase(1) - , _scalingOffset(0) { - } - - ParameterObject::ParameterObject(cip::CipUint instanceId, bool fullAttributes, - const SessionInfoIf::SPtr &si, - const MessageRouter::SPtr& messageRouter) - : BaseObject(CLASS_ID, instanceId) - , _name{""} - , _hasFullAttributes{fullAttributes} - , _isScalable{false} - , _messageRouter{messageRouter} { + ParameterObject::ParameterObject(cip::CipUint instanceId, bool fullAttributes, size_t typeSize) + : BaseObject(CLASS_ID, instanceId) + , _hasFullAttributes(fullAttributes) + , _value(typeSize) + , _maxValue(typeSize) + , _minValue(typeSize) + , _defaultValue(typeSize) + , _isScalable(false) + , _isReadOnly(false) + , _scalingMultiplier(1) + , _scalingDivisor(1) + , _scalingBase(1) + , _scalingOffset(0) + , _precision(0) { + } + + ParameterObject::ParameterObject(cip::CipUint instanceId, bool fullAttributes, + const SessionInfoIf::SPtr &si, + const MessageRouter::SPtr& messageRouter) + : BaseObject(CLASS_ID, instanceId) + , _name{""} + , _hasFullAttributes{fullAttributes} + , _isScalable{false} + , _isReadOnly(false) + , _scalingMultiplier(1) + , _scalingDivisor(1) + , _scalingBase(1) + , _scalingOffset(0) + , _precision(0) + , _messageRouter{messageRouter} { Logger(LogLevel::DEBUG) << "Read data from parameter ID=" << instanceId; @@ -103,7 +110,8 @@ namespace eipScanner { CipWord descriptor; buffer >> descriptor >> reinterpret_cast(_type); - _isScalable = descriptor & DescriptorAttributeBits::SUPPORTS_SCALING; + _parameter = instanceId; + _isScalable = descriptor & DescriptorAttributeBits::SUPPORTS_SCALING; _isReadOnly = descriptor & DescriptorAttributeBits::READ_ONLY; Logger(LogLevel::DEBUG) << "Parameter object ID=" << instanceId << " has descriptor=0x" << std::hex << descriptor @@ -209,6 +217,10 @@ namespace eipScanner { return _help; } + const cip::CipUint &ParameterObject::getParameter() const { + return _parameter; + } + CipUint ParameterObject::getScalingMultiplier() const { return _scalingMultiplier; } diff --git a/src/ParameterObject.h b/src/ParameterObject.h index 4238a32..55c006f 100644 --- a/src/ParameterObject.h +++ b/src/ParameterObject.h @@ -254,6 +254,12 @@ class ParameterObject : public BaseObject { */ const std::string &getHelp() const; + /** + * @brief Gets the number of parameter (instance ID) + * @return + */ + const cip::CipUint &getParameter() const; + /** * @brief Sets the name [AttrID=7] of the parameter * @param name @@ -356,6 +362,7 @@ class ParameterObject : public BaseObject { bool _isScalable; bool _isReadOnly; + cip::CipUint _parameter; std::vector _value; cip::CipDataTypes _type; std::string _name;