aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/view.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-12-14 21:49:58 +0100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-12-14 21:49:58 +0100
commitad0780c7163c9673f89dc584d2a6096f317bec2b (patch)
tree68a2b846e34dfc86944d76339400ecb40038e6e1 /src/view.c
parent376c62bc63870fa1121548fc8b53271c21ed79a6 (diff)
avoid FILENAME_MAX for allocating on the stack
* FILENAME_MAX is a standard C macro, but it may be arbitrarily long on some platforms (like the popular GNU/Hurd). See: https://www.gnu.org/software/libc/manual/html_node/Limits-for-Files.html#index-FILENAME_005fMAX * This means there is no portable macro for the maximum path length. You could perhaps define PATH_MAX to MAX_PATH on Windows. * Instead, we use g_strdup_printf() to calculate the save point name. We avoid another g_build_filename() by prepending the directory in the printf().
Diffstat (limited to 'src/view.c')
-rw-r--r--src/view.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/view.c b/src/view.c
index 53199bd..eeb4d3d 100644
--- a/src/view.c
+++ b/src/view.c
@@ -466,13 +466,10 @@ teco_undo_restore_savepoint_push(gchar *savepoint, const gchar *filename)
static void
teco_make_savepoint(const gchar *filename)
{
- gchar savepoint_basename[FILENAME_MAX];
-
g_autofree gchar *basename = g_path_get_basename(filename);
- g_snprintf(savepoint_basename, sizeof(savepoint_basename),
- ".teco-%d-%s~", savepoint_id, basename);
g_autofree gchar *dirname = g_path_get_dirname(filename);
- gchar *savepoint = g_build_filename(dirname, savepoint_basename, NULL);
+ gchar *savepoint = g_strdup_printf("%s%c.teco-%d-%s~", dirname, G_DIR_SEPARATOR,
+ savepoint_id, basename);
if (g_rename(filename, savepoint)) {
teco_interface_msg(TECO_MSG_WARNING,