diff --git a/documentation/src/editor.dox b/documentation/src/editor.dox
index fb93e63b7e54f35f21653771bd4e675a4b8236ab..8d9d2fb1e2b54a16cbf24c14680ef9946defbb57 100644
--- a/documentation/src/editor.dox
+++ b/documentation/src/editor.dox
@@ -131,6 +131,7 @@ void update_title() {
     fname = fl_filename_name(app_filename);
   if (fname) {
     char buf[FL_PATH_MAX + 3];
+    buf[FL_PATH_MAX + 2] = '\0';   // ensure that the buffer is always terminated
     if (text_changed) {
       snprintf(buf, FL_PATH_MAX+2, "%s *", fname);
     } else {
diff --git a/test/editor.cxx b/test/editor.cxx
index 043066108eec413ba55bb6a42acf4907b1cf0221..c989b9dd79f45893c7e93bb2e4dec73cdd31b8a4 100644
--- a/test/editor.cxx
+++ b/test/editor.cxx
@@ -4,7 +4,7 @@
 // This program is described in chapter "Designing a Simple Text Editor"
 // of the FLTK Programmer's Guide.
 //
-// Copyright 1998-2024 by Bill Spitzak and others.
+// Copyright 1998-2025 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -61,6 +61,7 @@ void update_title() {
     fname = fl_filename_name(app_filename);
   if (fname) {
     char buf[FL_PATH_MAX + 3];
+    buf[FL_PATH_MAX + 2] = '\0';   // ensure that the buffer is always terminated
     if (text_changed) {
       snprintf(buf, FL_PATH_MAX+2, "%s *", fname);
     } else {