From eaf5fb8d1153a1384db0c5ae645e36ef84a9da51 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser <albrechts.fltk@online.de> Date: Wed, 19 Feb 2025 17:22:16 +0100 Subject: [PATCH] Fix buffer overflow warning [-Wstringop-truncation] Note: this fixes the warning, but a better fix would be to use either strlcpy(), fl_strlcpy(), or a string type in 1.5.0 or higher. --- fluid/fluid.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index b63ebe672..c8b2292d1 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -1936,7 +1936,6 @@ void load_history() { int i; // Looping var int max_files; - fluid_prefs.get("recent_files", max_files, 5); if (max_files > 10) max_files = 10; @@ -1945,7 +1944,7 @@ void load_history() { if (absolute_history[i][0]) { // Make a shortened version of the filename for the menu... Fl_String fn = fl_filename_shortened(absolute_history[i], 48); - strncpy(relative_history[i], fn.c_str(), sizeof(relative_history[i])); + strncpy(relative_history[i], fn.c_str(), sizeof(relative_history[i]) - 1); if (i == 9) history_item[i].flags = FL_MENU_DIVIDER; else history_item[i].flags = 0; } else break; @@ -2005,7 +2004,7 @@ void update_history(const char *flname) { // Put the new file at the top... strlcpy(absolute_history[0], absolute, sizeof(absolute_history[0])); Fl_String fn = fl_filename_shortened(absolute_history[0], 48); - strncpy(relative_history[0], fn.c_str(), sizeof(relative_history[0])); + strncpy(relative_history[0], fn.c_str(), sizeof(relative_history[0]) - 1); // Update the menu items as needed... for (i = 0; i < max_files; i ++) { -- GitLab