From 2178ff1c48267e7a82a8b4484cd9fb3d018888d2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 27 Apr 2021 15:07:27 +0530 Subject: [PATCH] DRYer --- kitty/disk-cache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kitty/disk-cache.c b/kitty/disk-cache.c index b26fefbff..5c7f43edc 100644 --- a/kitty/disk-cache.c +++ b/kitty/disk-cache.c @@ -84,10 +84,11 @@ new(PyTypeObject *type, PyObject UNUSED *args, PyObject UNUSED *kwds) { static int open_cache_file_without_tmpfile(const char *cache_path) { int fd = -1; - size_t sz = strlen(cache_path) + 16; + static const char *template = "%s/disk-cache-XXXXXXXXXXXX"; + size_t sz = strlen(cache_path) + sizeof(template); FREE_AFTER_FUNCTION char *buf = calloc(1, sz); if (!buf) { errno = ENOMEM; return -1; } - snprintf(buf, sz - 1, "%s/disk-cache-XXXXXXXXXXXX", cache_path); + snprintf(buf, sz - 1, template, cache_path); while (fd < 0) { fd = mkostemp(buf, O_CLOEXEC); if (fd > -1 || errno != EINTR) break;