aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-08-10 11:40:03 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-08-10 11:40:03 +0300
commitf22bc5171f733d1f9a6f3daeab8233386e79c320 (patch)
treee439f502215548827d81b5cc8fb192fab7c311f6 /src
parent20b5a04370ac987807af73526b22dfe6e8a08a3d (diff)
downloadsciteco-f22bc5171f733d1f9a6f3daeab8233386e79c320.tar.gz
allow messages to be of arbitrary length: fixes crashes
* Messages can be arbitrarily long, e.g. the following could provoke crashes in interactive mode `1000<@I/X/> HX$` It's hard to turn into a test case, though, as you could always increase the buffer size in teco_interface_msg(). * The message length is now only limited by RAM. * This implementation is less effective, but code opting for efficience, including all programmable user messages, should not rely on the printf-API anyway but use teco_interface_msg_literal().
Diffstat (limited to 'src')
-rw-r--r--src/interface.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/interface.c b/src/interface.c
index cfc8279..8685990 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -20,6 +20,7 @@
#endif
#include <stdarg.h>
+#include <string.h>
#include <stdio.h>
#include <glib.h>
@@ -87,19 +88,13 @@ teco_interface_undo_set_clipboard(const gchar *name, gchar *str, gsize len)
void
teco_interface_msg(teco_msg_t type, const gchar *fmt, ...)
{
- gchar buf[512];
va_list ap;
va_start(ap, fmt);
- /*
- * If the buffer could ever be exceeded, perhaps
- * use g_strdup_vprintf() instead.
- */
- gint len = g_vsnprintf(buf, sizeof(buf), fmt, ap);
- g_assert(0 <= len && len < sizeof(buf));
+ g_autofree gchar *buf = g_strdup_vprintf(fmt, ap);
va_end(ap);
- teco_interface_msg_literal(type, buf, len);
+ teco_interface_msg_literal(type, buf, strlen(buf));
}
/**