From 0880399fbe4d5c273858a20fec1a1a84a4e0862a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 5 Nov 2023 12:30:54 +1100 Subject: [PATCH] Replace snprintf with format_to --- src/backtrace.cc | 3 ++- src/highlighters.cc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/backtrace.cc b/src/backtrace.cc index 950770e9..1b3c6d09 100644 --- a/src/backtrace.cc +++ b/src/backtrace.cc @@ -1,6 +1,7 @@ #include "backtrace.hh" #include "string.hh" +#include "string_utils.hh" #if defined(__GLIBC__) || defined(__APPLE__) # include @@ -62,7 +63,7 @@ String Backtrace::desc() const { SymFromAddr(process, (DWORD64)stackframes[i], 0, symbol_info); 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; } return res; diff --git a/src/highlighters.cc b/src/highlighters.cc index de1dcb04..7e6bd1c0 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1117,7 +1117,7 @@ private: int digit_count = compute_digit_count(context.context); 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; int last_line = -1; for (auto& line : display_buffer.lines()) @@ -1127,7 +1127,7 @@ private: const int line_to_format = (m_relative and not is_cursor_line) ? current_line - main_line : current_line; 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 : ((m_hl_cursor_line and is_cursor_line) ? face_absolute : face);