szaszm commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r437540894



##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + 
FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() 
+ 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) 
+ FlowControlMsgIDEncodingLen(FLOW_YML_NAME, 
gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       Normally `gsl::narrow<T>` calls `std::terminate()` on failed conversion. 
I set the config options to change the behavior to throwing an exception in 
release builds, but we should normally not rely on this.
   
   The motivation here is to fail early at runtime instead of invoking 
undefined behavior. It should never fail, and if it does, it's a programming 
error. This should be a hard error, not an exception.

##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + 
FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() 
+ 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) 
+ FlowControlMsgIDEncodingLen(FLOW_YML_NAME, 
gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       Normally `gsl::narrow<T>` calls `std::terminate()` on failed conversion. 
I set the config options to change the behavior to throwing an exception in 
release builds by default, but we should normally not rely on this.
   
   The motivation here is to fail early at runtime instead of invoking 
undefined behavior. It should never fail, and if it does, it's a programming 
error. This should be a hard error, not an exception.

##########
File path: libminifi/include/FlowController.h
##########
@@ -50,6 +51,7 @@
 #include "utils/Id.h"
 #include "core/state/UpdateController.h"
 #include "core/state/nodes/FlowInformation.h"
+#include "utils/gsl.h"

Review comment:
       Redundant include

##########
File path: extensions/librdkafka/PublishKafka.cpp
##########
@@ -31,6 +31,7 @@
 #include "utils/StringUtils.h"
 #include "utils/ScopeGuard.h"
 #include "utils/GeneralUtils.h"
+#include "utils/gsl.h"

Review comment:
       Redundant include

##########
File path: extensions/librdkafka/PublishKafka.cpp
##########
@@ -31,6 +31,7 @@
 #include "utils/StringUtils.h"
 #include "utils/ScopeGuard.h"
 #include "utils/GeneralUtils.h"
+#include "utils/gsl.h"

Review comment:
       2259722

##########
File path: libminifi/include/FlowController.h
##########
@@ -50,6 +51,7 @@
 #include "utils/Id.h"
 #include "core/state/UpdateController.h"
 #include "core/state/nodes/FlowInformation.h"
+#include "utils/gsl.h"

Review comment:
       2259722




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to