Don't over-allocate the active effect slot array
[openal-soft.git] / core / except.cpp
blobf338e9aeb2df1f7c5d786e529e8a2a3890ba6e02
2 #include "config.h"
4 #include "except.h"
6 #include <cstdio>
7 #include <cstdarg>
9 #include "opthelpers.h"
12 namespace al {
14 base_exception::~base_exception() = default;
16 void base_exception::setMessage(const char *msg, std::va_list args)
18 /* NOLINTBEGIN(*-array-to-pointer-decay) */
19 std::va_list args2;
20 va_copy(args2, args);
21 int msglen{std::vsnprintf(nullptr, 0, msg, args)};
22 if(msglen > 0) LIKELY
24 mMessage.resize(static_cast<size_t>(msglen)+1);
25 std::vsnprintf(mMessage.data(), mMessage.length(), msg, args2);
26 mMessage.pop_back();
28 va_end(args2);
29 /* NOLINTEND(*-array-to-pointer-decay) */
32 } // namespace al