Escape FLTK menu entries
We don't want it automatically creating submenus when least
expected.
diff --git a/vncviewer/fltk_layout.h b/vncviewer/fltk_layout.h
index c16a359..21fb00a 100644
--- a/vncviewer/fltk_layout.h
+++ b/vncviewer/fltk_layout.h
@@ -20,6 +20,7 @@
#define __FLTK_LAYOUT_H__
#include <FL/fl_draw.H>
+#include <FL/Fl_Menu_.H>
/* Calculates the width of a string as printed by FLTK (pixels) */
static inline int gui_str_len(const char *str)
@@ -67,6 +68,53 @@
return len;
}
+/* Filter out unsafe characters for menu entries */
+static inline int fltk_menu_escape(const char *in, char *out, size_t maxlen)
+{
+ int len;
+
+ len = 0;
+
+ while (*in != '\0') {
+ if (*in == '/') {
+ if (maxlen >= 3) {
+ *out++ = '\\';
+ *out++ = '/';
+ maxlen -= 2;
+ }
+
+ len += 2;
+ } else {
+ if (maxlen >= 2) {
+ *out++ = *in;
+ maxlen--;
+ }
+
+ len += 1;
+ }
+
+ in++;
+ }
+
+ if (maxlen)
+ *out = '\0';
+
+ return len;
+}
+
+/* Helper to add menu entries safely */
+static inline void fltk_menu_add(Fl_Menu_ *menu, const char *text,
+ int shortcut, Fl_Callback *cb,
+ void *data = 0, int flags = 0)
+{
+ char buffer[1024];
+
+ if (fltk_menu_escape(text, buffer, sizeof(buffer)) >= sizeof(buffer))
+ return;
+
+ menu->add(buffer, shortcut, cb, data, flags);
+}
+
/**** MARGINS ****/
#define OUTER_MARGIN 10