nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite
Date Tue, 09 Jun 2020 16:40:13 GMT

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



##########
File path: libminifi/include/utils/ScopeGuard.h
##########
@@ -22,39 +22,19 @@
 
 #include <functional>
 
+#include "gsl.h"
+
 namespace org {
 namespace apache {
 namespace nifi {
 namespace minifi {
 namespace utils {
 
-class ScopeGuard {
- private:
-  bool enabled_;
-  std::function<void()> func_;
-
- public:
-  explicit ScopeGuard(std::function<void()>&& func)
-    : enabled_(true)
-    , func_(std::move(func)) {
-  }
-
-  ~ScopeGuard() {
-    if (enabled_) {
-      try {
-        func_();
-      } catch (...) {
-      }
-    }
-  }
-
-  ScopeGuard(const ScopeGuard&) = delete;
-  ScopeGuard(ScopeGuard&&) = delete;
-  ScopeGuard& operator=(const ScopeGuard&) = delete;
-  ScopeGuard& operator=(ScopeGuard&&) = delete;
+struct ScopeGuard : ::gsl::final_action<std::function<void()>> {

Review comment:
       👍 

##########
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:
       I don't see any try catch block around this.
   
   Maybe we should catch and log narrowing exceptions in `FlowControlProtocol::run()`, so
that if the thread catches due to them we see the reson.

##########
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:
       I don't see any try catch block around this.
   
   Maybe we should catch and log narrowing exceptions in `FlowControlProtocol::run()`, so
that if the thread catches due to them we see the reason.




----------------------------------------------------------------
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:
users@infra.apache.org



Mime
View raw message