except.cpp 610 B

12345678910111213141516171819202122232425262728293031
  1. #include "config.h"
  2. #include "except.h"
  3. #include <cstdio>
  4. #include <cstdarg>
  5. #include "opthelpers.h"
  6. namespace al {
  7. /* Defined here to avoid inlining it. */
  8. base_exception::~base_exception() { }
  9. void base_exception::setMessage(const char* msg, std::va_list args)
  10. {
  11. std::va_list args2;
  12. va_copy(args2, args);
  13. int msglen{std::vsnprintf(nullptr, 0, msg, args)};
  14. if LIKELY(msglen > 0)
  15. {
  16. mMessage.resize(static_cast<size_t>(msglen)+1);
  17. std::vsnprintf(&mMessage[0], mMessage.length(), msg, args2);
  18. mMessage.pop_back();
  19. }
  20. va_end(args2);
  21. }
  22. } // namespace al