Fixes out of scope pointer returned from websocketpp::exception::what(); fixes #397
Also adds unit tests for exception construction
This commit is contained in:
1 parent
d55f28fe4b
commit
681c2331a1
4 files changed
+67
-11
No files matched your search
@@ -34,6 +34,8 @@ HEAD
|
||||
immediately after that handshake times out. #389
|
||||
- Bug: MinGW fixes; C++11 feature detection, localtime use. #393 Thank you
|
||||
Schebb for reporting, code, and testing.
|
||||
- Bug: Fixes an issue where `websocketpp::exception::what()` could return an out
|
||||
of scope pointer. #397 Thank you fabioang for reporting.
|
||||
|
||||
0.4.0 - 2014-11-04
|
||||
- BREAKING API CHANGE: All WebSocket++ methods now throw an exception of type
|
||||
|
||||
@@ -16,11 +16,13 @@ objs = env.Object('uri_boost.o', ["uri.cpp"], LIBS = BOOST_LIBS)
|
||||
objs += env.Object('utilities_boost.o', ["utilities.cpp"], LIBS = BOOST_LIBS)
|
||||
objs += env.Object('close_boost.o', ["close.cpp"], LIBS = BOOST_LIBS)
|
||||
objs += env.Object('sha1_boost.o', ["sha1.cpp"], LIBS = BOOST_LIBS)
|
||||
objs += env.Object('error_boost.o', ["error.cpp"], LIBS = BOOST_LIBS)
|
||||
prgs = env.Program('test_uri_boost', ["uri_boost.o"], LIBS = BOOST_LIBS)
|
||||
prgs += env.Program('test_utility_boost', ["utilities_boost.o"], LIBS = BOOST_LIBS)
|
||||
prgs += env.Program('test_frame', ["frame.cpp"], LIBS = BOOST_LIBS)
|
||||
prgs += env.Program('test_close_boost', ["close_boost.o"], LIBS = BOOST_LIBS)
|
||||
prgs += env.Program('test_sha1_boost', ["sha1_boost.o"], LIBS = BOOST_LIBS)
|
||||
prgs += env.Program('test_error_boost', ["error_boost.o"], LIBS = BOOST_LIBS)
|
||||
|
||||
if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
|
||||
BOOST_LIBS_CPP11 = boostlibs(['unit_test_framework'],env_cpp11) + [platform_libs] + [polyfill_libs]
|
||||
@@ -28,9 +30,11 @@ if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
|
||||
objs += env_cpp11.Object('uri_stl.o', ["uri.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('close_stl.o', ["close.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('sha1_stl.o', ["sha1.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('error_stl.o', ["error.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_utility_stl', ["utilities_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_uri_stl', ["uri_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_close_stl', ["close_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_sha1_stl', ["sha1_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_error_stl', ["error_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
|
||||
Return('prgs')
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE error
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <websocketpp/error.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE( constructing_exceptions ) {
|
||||
websocketpp::lib::error_code test_ec = websocketpp::error::make_error_code(websocketpp::error::test);
|
||||
websocketpp::lib::error_code general_ec = websocketpp::error::make_error_code(websocketpp::error::general);
|
||||
|
||||
websocketpp::exception b("foo");
|
||||
websocketpp::exception c("foo",test_ec);
|
||||
websocketpp::exception d("");
|
||||
websocketpp::exception e("",test_ec);
|
||||
|
||||
BOOST_CHECK_EQUAL(b.what(),"foo");
|
||||
BOOST_CHECK_EQUAL(b.code(),general_ec);
|
||||
|
||||
BOOST_CHECK_EQUAL(c.what(),"foo");
|
||||
BOOST_CHECK_EQUAL(c.code(),test_ec);
|
||||
|
||||
BOOST_CHECK_EQUAL(d.what(),"Generic error");
|
||||
BOOST_CHECK_EQUAL(d.code(),general_ec);
|
||||
|
||||
BOOST_CHECK_EQUAL(e.what(),"Test Error");
|
||||
BOOST_CHECK_EQUAL(e.code(),test_ec);
|
||||
}
|
||||
|
||||
+7
-11
@@ -125,20 +125,20 @@ enum value {
|
||||
|
||||
/// The requested operation was canceled
|
||||
operation_canceled,
|
||||
|
||||
|
||||
/// Connection rejected
|
||||
rejected,
|
||||
|
||||
|
||||
/// Upgrade Required. This happens if an HTTP request is made to a
|
||||
/// WebSocket++ server that doesn't implement an http handler
|
||||
upgrade_required,
|
||||
|
||||
|
||||
/// Invalid WebSocket protocol version
|
||||
invalid_version,
|
||||
|
||||
|
||||
/// Unsupported WebSocket protocol version
|
||||
unsupported_version,
|
||||
|
||||
|
||||
/// HTTP parse error
|
||||
http_parse_error
|
||||
}; // enum value
|
||||
@@ -246,7 +246,7 @@ namespace websocketpp {
|
||||
class exception : public std::exception {
|
||||
public:
|
||||
exception(std::string const & msg, lib::error_code ec = make_error_code(error::general))
|
||||
: m_msg(msg), m_code(ec)
|
||||
: m_msg(msg.empty() ? ec.message() : msg), m_code(ec)
|
||||
{}
|
||||
|
||||
explicit exception(lib::error_code ec)
|
||||
@@ -256,11 +256,7 @@ public:
|
||||
~exception() throw() {}
|
||||
|
||||
virtual char const * what() const throw() {
|
||||
if (m_msg.empty()) {
|
||||
return m_code.message().c_str();
|
||||
} else {
|
||||
return m_msg.c_str();
|
||||
}
|
||||
return m_msg.c_str();
|
||||
}
|
||||
|
||||
lib::error_code code() const throw() {
|
||||
|
||||
Reference in new issue
Block a user