qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-proton git commit: NO-JIRA: c++ fix invalid conversion of NULL char* to std::string
Date Wed, 27 Apr 2016 14:38:08 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master bfb5d19d4 -> b53a684e7


NO-JIRA: c++ fix invalid conversion of NULL char* to std::string


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b53a684e
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b53a684e
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b53a684e

Branch: refs/heads/master
Commit: b53a684e7d28c99193fb9529c4c0571968fccb18
Parents: bfb5d19
Author: Alan Conway <aconway@redhat.com>
Authored: Wed Apr 27 10:34:49 2016 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Wed Apr 27 10:36:52 2016 -0400

----------------------------------------------------------------------
 proton-c/bindings/cpp/src/connection.cpp  | 8 +++++---
 proton-c/bindings/cpp/src/link.cpp        | 5 ++++-
 proton-c/bindings/cpp/src/proton_bits.hpp | 3 +++
 proton-c/bindings/cpp/src/source.cpp      | 5 +++--
 proton-c/bindings/cpp/src/target.cpp      | 4 +++-
 proton-c/bindings/cpp/src/terminus.cpp    | 5 +++--
 6 files changed, 21 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b53a684e/proton-c/bindings/cpp/src/connection.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/connection.cpp b/proton-c/bindings/cpp/src/connection.cpp
index 4100843..e705fc6 100644
--- a/proton-c/bindings/cpp/src/connection.cpp
+++ b/proton-c/bindings/cpp/src/connection.cpp
@@ -18,6 +18,9 @@
  * under the License.
  *
  */
+
+#include "proton_bits.hpp"
+
 #include "proton/connection.hpp"
 
 #include "proton/container.hpp"
@@ -56,7 +59,7 @@ void connection::close() { pn_connection_close(pn_object()); }
 void connection::release() { pn_connection_release(pn_object()); }
 
 std::string connection::host() const {
-    return std::string(pn_connection_get_hostname(pn_object()));
+    return str(pn_connection_get_hostname(pn_object()));
 }
 
 void connection::host(const std::string& h) {
@@ -64,8 +67,7 @@ void connection::host(const std::string& h) {
 }
 
 std::string connection::container_id() const {
-    const char* id = pn_connection_get_container(pn_object());
-    return id ? std::string(id) : std::string();
+    return str(pn_connection_get_container(pn_object()));
 }
 
 container& connection::container() const {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b53a684e/proton-c/bindings/cpp/src/link.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/link.cpp b/proton-c/bindings/cpp/src/link.cpp
index de431d5..b1e8e60 100644
--- a/proton-c/bindings/cpp/src/link.cpp
+++ b/proton-c/bindings/cpp/src/link.cpp
@@ -18,6 +18,9 @@
  * under the License.
  *
  */
+
+#include "proton_bits.hpp"
+
 #include "proton/link.hpp"
 #include "proton/error.hpp"
 #include "proton/connection.hpp"
@@ -53,7 +56,7 @@ int link::queued() { return pn_link_queued(pn_object()); }
 int link::unsettled() { return pn_link_unsettled(pn_object()); }
 int link::drained() { return pn_link_drained(pn_object()); }
 
-std::string link::name() const { return std::string(pn_link_name(pn_object()));}
+std::string link::name() const { return str(pn_link_name(pn_object()));}
 
 container& link::container() const {
     return connection().container();

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b53a684e/proton-c/bindings/cpp/src/proton_bits.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/proton_bits.hpp b/proton-c/bindings/cpp/src/proton_bits.hpp
index a53eaf0..0c244c5 100644
--- a/proton-c/bindings/cpp/src/proton_bits.hpp
+++ b/proton-c/bindings/cpp/src/proton_bits.hpp
@@ -46,6 +46,9 @@ std::ostream& operator<<(std::ostream& o, const inspectable&
object);
 
 void set_error_condition(const error_condition&, pn_condition_t*);
 
+/// Convert a const char* to std::string, convert NULL to the empty string.
+inline std::string str(const char* s) { return s ? s : ""; }
+
 }
 
 #endif // PROTON_BITS_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b53a684e/proton-c/bindings/cpp/src/source.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/source.cpp b/proton-c/bindings/cpp/src/source.cpp
index f840f63..95c76da 100644
--- a/proton-c/bindings/cpp/src/source.cpp
+++ b/proton-c/bindings/cpp/src/source.cpp
@@ -19,6 +19,8 @@
  *
  */
 
+#include "proton_bits.hpp"
+
 #include "proton/source.hpp"
 #include "proton/sender.hpp"
 #include "proton/receiver.hpp"
@@ -36,8 +38,7 @@ std::string source::address() const {
     pn_terminus_t *authoritative = object_;
     if (parent_ && pn_terminus_is_dynamic(object_))
         authoritative = pn_link_source(parent_);
-    return std::string(pn_terminus_get_address(authoritative));
+    return str(pn_terminus_get_address(authoritative));
 }
 
-
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b53a684e/proton-c/bindings/cpp/src/target.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/target.cpp b/proton-c/bindings/cpp/src/target.cpp
index db0126e..ee83670 100644
--- a/proton-c/bindings/cpp/src/target.cpp
+++ b/proton-c/bindings/cpp/src/target.cpp
@@ -19,6 +19,8 @@
  *
  */
 
+#include "proton_bits.hpp"
+
 #include "proton/target.hpp"
 #include "proton/sender.hpp"
 #include "proton/receiver.hpp"
@@ -34,7 +36,7 @@ std::string target::address() const {
     pn_terminus_t *authoritative = object_;
     if (parent_ && pn_terminus_is_dynamic(object_))
         authoritative = pn_link_target(parent_);
-    return std::string(pn_terminus_get_address(authoritative));
+    return str(pn_terminus_get_address(authoritative));
 }
 
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b53a684e/proton-c/bindings/cpp/src/terminus.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/terminus.cpp b/proton-c/bindings/cpp/src/terminus.cpp
index 582bfcd..494c09c 100644
--- a/proton-c/bindings/cpp/src/terminus.cpp
+++ b/proton-c/bindings/cpp/src/terminus.cpp
@@ -19,6 +19,8 @@
  *
  */
 
+#include "proton_bits.hpp"
+
 #include "proton/link.hpp"
 #include "proton/link.h"
 
@@ -76,8 +78,7 @@ void terminus::durability_mode(enum durability_mode d) {
 }
 
 std::string terminus::address() const {
-    const char *addr = pn_terminus_get_address(object_);
-    return addr ? std::string(addr) : std::string();
+    return str(pn_terminus_get_address(object_));
 }
 
 void terminus::address(const std::string &addr) {


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


Mime
View raw message