From 64e0b6e3f8edcb114c5fef8e5d15158740aa21c7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 2 Apr 2015 13:58:06 +0100 Subject: [PATCH] Replace a snprintf with format in backup file name generation --- src/file.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/file.cc b/src/file.cc index dfffb043..ee367144 100644 --- a/src/file.cc +++ b/src/file.cc @@ -231,15 +231,10 @@ void write_buffer_to_backup_file(Buffer& buffer) StringView dir, file; std::tie(dir,file) = split_path(path); - char pattern[PATH_MAX+1]; - if (not dir.empty()) - snprintf(pattern, PATH_MAX+1, "%s/.%s.kak.XXXXXX", - (const char*)dir.zstr(), (const char*) file.zstr()); - else - snprintf(pattern, PATH_MAX+1, ".%s.kak.XXXXXX", - (const char*)file.zstr()); + String pattern = dir.empty() ? format(".{}.kak.XXXXXX", file) + : format("{}/.{}.kak.XXXXXX", dir, file); - int fd = mkstemp(pattern); + int fd = mkstemp(&pattern[0]); if (fd >= 0) { write_buffer_to_fd(buffer, fd);