Replace snprintf with format_to

This commit is contained in:
Maxime Coste 2023-11-05 12:30:54 +11:00
parent 465e0280d8
commit 0880399fbe
2 changed files with 4 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include "backtrace.hh" #include "backtrace.hh"
#include "string.hh" #include "string.hh"
#include "string_utils.hh"
#if defined(__GLIBC__) || defined(__APPLE__) #if defined(__GLIBC__) || defined(__APPLE__)
# include <execinfo.h> # include <execinfo.h>
@ -62,7 +63,7 @@ String Backtrace::desc() const
{ {
SymFromAddr(process, (DWORD64)stackframes[i], 0, symbol_info); SymFromAddr(process, (DWORD64)stackframes[i], 0, symbol_info);
char desc[276]; char desc[276];
snprintf(desc, 276, "0x%0llx (%s)\n", symbol_info->Address, symbol_info->Name); format_to(desc, "0x{} ({})\n", hex(symbol_info->Address), symbol_info->Name);
res += desc; res += desc;
} }
return res; return res;

View File

@ -1117,7 +1117,7 @@ private:
int digit_count = compute_digit_count(context.context); int digit_count = compute_digit_count(context.context);
char format[16]; char format[16];
format_to(format, "%{}d", digit_count); format_to(format, "\\{:{}}", digit_count);
const int main_line = (int)context.context.selections().main().cursor().line + 1; const int main_line = (int)context.context.selections().main().cursor().line + 1;
int last_line = -1; int last_line = -1;
for (auto& line : display_buffer.lines()) for (auto& line : display_buffer.lines())
@ -1127,7 +1127,7 @@ private:
const int line_to_format = (m_relative and not is_cursor_line) ? const int line_to_format = (m_relative and not is_cursor_line) ?
current_line - main_line : current_line; current_line - main_line : current_line;
char buffer[16]; char buffer[16];
snprintf(buffer, 16, format, std::abs(line_to_format)); format_to(buffer, format, std::abs(line_to_format));
const auto atom_face = last_line == current_line ? face_wrapped : const auto atom_face = last_line == current_line ? face_wrapped :
((m_hl_cursor_line and is_cursor_line) ? face_absolute : face); ((m_hl_cursor_line and is_cursor_line) ? face_absolute : face);