You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2023/01/30 23:00:31 UTC

[qpid-proton] 02/02: PROTON-2657: Fix an issue found by Coverity

This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 6ae2654a4eebfd3108544775bbc5d40a015665f0
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Mon Jan 30 17:54:50 2023 -0500

    PROTON-2657: Fix an issue found by Coverity
    
    If you try to get  the user_data value before it is set it might be
    uninitialised.
    
    Also improve some pointer usage in contexts to use C++ 11 nullptr.
---
 cpp/src/contexts.cpp | 4 ++--
 cpp/src/contexts.hpp | 9 +++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/cpp/src/contexts.cpp b/cpp/src/contexts.cpp
index 4f85ace93..a3b393968 100644
--- a/cpp/src/contexts.cpp
+++ b/cpp/src/contexts.cpp
@@ -66,14 +66,14 @@ void *context::alloc(size_t n) { return pn_class_new(cpp_context_class, n); }
 pn_class_t* context::pn_class() { return cpp_context_class; }
 
 connection_context::connection_context() :
-    container(0), default_session(0), link_gen(0), handler(0), listener_context_(0)
+    container(nullptr), default_session(nullptr), link_gen(nullptr), handler(nullptr), listener_context_(nullptr), user_data_(nullptr)
 {}
 
 reconnect_context::reconnect_context(const reconnect_options_base& ro) :
     reconnect_options_(ro), retries_(0), current_url_(-1), stop_reconnect_(false), reconnected_(false)
 {}
 
-listener_context::listener_context() : listen_handler_(0) {}
+listener_context::listener_context() : listen_handler_(nullptr), user_data_(nullptr) {}
 
 connection_context& connection_context::get(pn_connection_t *c) {
     return ref<connection_context>(id(pn_connection_attachments(c), CONNECTION_CONTEXT));
diff --git a/cpp/src/contexts.hpp b/cpp/src/contexts.hpp
index 02ea76083..7ebab1d7b 100644
--- a/cpp/src/contexts.hpp
+++ b/cpp/src/contexts.hpp
@@ -133,7 +133,9 @@ class listener_context : public context {
 
 class link_context : public context {
   public:
-    link_context() : handler(0), credit_window(10), pending_credit(0), auto_accept(true), auto_settle(true), draining(false) {}
+    link_context() :
+      handler(nullptr), credit_window(10), pending_credit(0), auto_accept(true), auto_settle(true), draining(false), user_data_(nullptr)
+    {}
     static link_context& get(pn_link_t* l);
 
     messaging_handler* handler;
@@ -147,7 +149,7 @@ class link_context : public context {
 
 class session_context : public context {
   public:
-    session_context() : handler(0) {}
+    session_context() : handler(0), user_data_(nullptr) {}
     static session_context& get(pn_session_t* s);
 
     messaging_handler* handler;
@@ -156,10 +158,9 @@ class session_context : public context {
 
 class transfer_context : public context {
   public:
-    transfer_context() : handler(0) {}
+    transfer_context() : user_data_(nullptr) {}
     static transfer_context& get(pn_delivery_t* s);
 
-    messaging_handler* handler;
     void* user_data_;
 };
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org