From 1e8670bd64efcc51cb435880a4e11337c56b1a0f Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Fri, 30 Sep 2016 19:59:31 +0200
Subject: Add missing error check in HostAddress::toString

In the process converted try/catch use to Boost's error code
for more explicit error checking and added log output.

Test-Information:

Swift builds with test=all on macOS 10.12 and all tests pass.

Change-Id: I6e465354dbb38c7178b0406b9a544ebd3be62ddd

diff --git a/Swiften/Network/HostAddress.cpp b/Swiften/Network/HostAddress.cpp
index 64a4ff6..7738079 100644
--- a/Swiften/Network/HostAddress.cpp
+++ b/Swiften/Network/HostAddress.cpp
@@ -7,7 +7,6 @@
 #include <Swiften/Network/HostAddress.h>
 
 #include <cassert>
-#include <stdexcept>
 #include <string>
 
 #include <boost/array.hpp>
@@ -15,6 +14,7 @@
 #include <boost/numeric/conversion/cast.hpp>
 
 #include <Swiften/Base/foreach.h>
+#include <Swiften/Base/Log.h>
 
 static boost::asio::ip::address localhost4 = boost::asio::ip::address(boost::asio::ip::address_v4::loopback());
 static boost::asio::ip::address localhost6 = boost::asio::ip::address(boost::asio::ip::address_v6::loopback());
@@ -25,10 +25,10 @@ HostAddress::HostAddress() {
 }
 
 HostAddress::HostAddress(const std::string& address) {
-    try {
-        address_ = boost::asio::ip::address::from_string(address);
-    }
-    catch (const std::exception&) {
+    boost::system::error_code errorCode;
+    address_ = boost::asio::ip::address::from_string(address, errorCode);
+    if (errorCode) {
+        SWIFT_LOG(warning) << "error: " << errorCode.message() << std::endl;
     }
 }
 
@@ -54,7 +54,15 @@ HostAddress::HostAddress(const boost::asio::ip::address& address) : address_(add
 }
 
 std::string HostAddress::toString() const {
-    return address_.to_string();
+    std::string addressString;
+    boost::system::error_code errorCode;
+
+    addressString = address_.to_string(errorCode);
+    if (errorCode) {
+        SWIFT_LOG(debug) << "error: " << errorCode.message() << std::endl;
+    }
+
+    return addressString;
 }
 
 bool HostAddress::isValid() const {
-- 
cgit v0.10.2-6-g49f6