| 90 | } |
| 91 | |
| 92 | FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code, |
| 93 | string_view message) noexcept { |
| 94 | // Report error code making sure that the output fits into inline_buffer_size |
| 95 | // to avoid dynamic memory allocation and potential bad_alloc. |
| 96 | out.try_resize(0); |
| 97 | static constexpr char SEP[] = ": "; |
| 98 | static constexpr char ERROR_STR[] = "error "; |
| 99 | // Subtract 2 to account for terminating null characters in SEP and ERROR_STR. |
| 100 | size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; |
| 101 | auto abs_value = static_cast<uint32_or_64_or_128_t<int>>(error_code); |
| 102 | if (detail::is_negative(error_code)) { |
| 103 | abs_value = 0 - abs_value; |
| 104 | ++error_code_size; |
| 105 | } |
| 106 | error_code_size += detail::to_unsigned(detail::count_digits(abs_value)); |
| 107 | auto it = appender(out); |
| 108 | if (message.size() <= inline_buffer_size - error_code_size) |
| 109 | fmt::format_to(it, FMT_STRING("{}{}"), message, SEP); |
| 110 | fmt::format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code); |
| 111 | FMT_ASSERT(out.size() <= inline_buffer_size, ""); |
| 112 | } |
| 113 | |
| 114 | FMT_FUNC void do_report_error(format_func func, int error_code, |
| 115 | const char* message) noexcept { |