aboutsummaryrefslogtreecommitdiffstats
path: root/common/alexcpt.cpp
blob: 6fbc63fd3eda8b3e01cb47754073b4d36f6399db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#include "config.h"

#include "alexcpt.h"

#include <cstdio>
#include <cstdarg>

#include "opthelpers.h"


namespace al {

/* Defined here to avoid inlining it. */
base_exception::~base_exception() { }

void base_exception::setMessage(const char* msg, std::va_list args)
{
    std::va_list args2;
    va_copy(args2, args);
    int msglen{std::vsnprintf(nullptr, 0, msg, args)};
    if LIKELY(msglen > 0)
    {
        mMessage.resize(static_cast<size_t>(msglen)+1);
        std::vsnprintf(&mMessage[0], mMessage.length(), msg, args2);
        mMessage.pop_back();
    }
    va_end(args2);
}

} // namespace al