From ad0780c7163c9673f89dc584d2a6096f317bec2b Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 14 Dec 2025 21:49:58 +0100 Subject: 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(). --- src/view.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/view.c') 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, -- cgit v1.2.3