except.cpp 673 B

1234567891011121314151617181920212223242526272829303132
  1. #include "config.h"
  2. #include "except.h"
  3. #include <cstdio>
  4. #include <cstdarg>
  5. #include "opthelpers.h"
  6. namespace al {
  7. base_exception::~base_exception() = default;
  8. void base_exception::setMessage(const char *msg, std::va_list args)
  9. {
  10. /* NOLINTBEGIN(*-array-to-pointer-decay) */
  11. std::va_list args2;
  12. va_copy(args2, args);
  13. int msglen{std::vsnprintf(nullptr, 0, msg, args)};
  14. if(msglen > 0) LIKELY
  15. {
  16. mMessage.resize(static_cast<size_t>(msglen)+1);
  17. std::vsnprintf(mMessage.data(), mMessage.length(), msg, args2);
  18. mMessage.pop_back();
  19. }
  20. va_end(args2);
  21. /* NOLINTEND(*-array-to-pointer-decay) */
  22. }
  23. } // namespace al