Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocketpp::exception::what() gives unexpected results #397

Closed
fabioang opened this issue Jan 14, 2015 · 2 comments
Closed

websocketpp::exception::what() gives unexpected results #397

fabioang opened this issue Jan 14, 2015 · 2 comments
Milestone

Comments

@fabioang
Copy link

When m_msg is empty what() returns a pointer which is out of scope

    virtual char const * what() const throw() {
        if (m_msg.empty()) {
            return m_code.message().c_str();   // temporary goes out of scope
        } else {
            return m_msg.c_str();
        }
    }

A possible solution could be:

    virtual char const * what() const throw() {
        if (m_msg.empty()) {
            m_msg = m_code.message().c_str();
        }
        return m_msg.c_str();
    }
private:
    mutable std::string m_msg; // added mutable
    lib::error_code m_code;

Regards,
Fabio

zaphoyd pushed a commit that referenced this issue Jan 22, 2015
…(); fixes #397

Also adds unit tests for exception construction
@zaphoyd zaphoyd added this to the 0.5.0 milestone Jan 22, 2015
@zaphoyd
Copy link
Owner

zaphoyd commented Jan 22, 2015

This should be fixed on the develop branch now

@zaphoyd
Copy link
Owner

zaphoyd commented Jan 22, 2015

The fix for this issue is now present in the 0.5.0 release on the master branch.

@zaphoyd zaphoyd closed this as completed Jan 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants