Revision: 4440
          http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4440&view=rev
Author:   ossman_
Date:     2011-05-23 12:21:21 +0000 (Mon, 23 May 2011)

Log Message:
-----------
We need to be careful about feeding FLTK @:s when they will be used in a
label as that is a formatting character.

Modified Paths:
--------------
    trunk/vncviewer/UserDialog.cxx
    trunk/vncviewer/Viewport.cxx
    trunk/vncviewer/fltk_layout.h

Modified: trunk/vncviewer/UserDialog.cxx
===================================================================
--- trunk/vncviewer/UserDialog.cxx      2011-05-23 11:21:22 UTC (rev 4439)
+++ trunk/vncviewer/UserDialog.cxx      2011-05-23 12:21:21 UTC (rev 4440)
@@ -34,6 +34,7 @@
 #include <rfb/Exception.h>
 
 #include "i18n.h"
+#include "fltk_layout.h"
 #include "parameters.h"
 #include "UserDialog.h"
 
@@ -137,6 +138,11 @@
 
 bool UserDialog::showMsgBox(int flags, const char* title, const char* text)
 {
+  char buffer[1024];
+
+  if (fltk_escape(text, buffer, sizeof(buffer)) >= sizeof(buffer))
+    return 0;
+
   // FLTK doesn't give us a flexible choice of the icon, so we ignore those
   // bits for now.
 
@@ -146,16 +152,16 @@
 
   switch (flags & 0xf) {
   case M_OKCANCEL:
-    return fl_choice(text, NULL, fl_ok, fl_cancel) == 1;
+    return fl_choice(buffer, NULL, fl_ok, fl_cancel) == 1;
   case M_YESNO:
-    return fl_choice(text, NULL, fl_yes, fl_no) == 1;
+    return fl_choice(buffer, NULL, fl_yes, fl_no) == 1;
   case M_OK:
   default:
     if (((flags & 0xf0) == M_ICONERROR) ||
         ((flags & 0xf0) == M_ICONWARNING))
-      fl_alert(text);
+      fl_alert(buffer);
     else
-      fl_message(text);
+      fl_message(buffer);
     return true;
   }
 

Modified: trunk/vncviewer/Viewport.cxx
===================================================================
--- trunk/vncviewer/Viewport.cxx        2011-05-23 11:21:22 UTC (rev 4439)
+++ trunk/vncviewer/Viewport.cxx        2011-05-23 12:21:21 UTC (rev 4440)
@@ -42,6 +42,7 @@
 #include "CConn.h"
 #include "OptionsDialog.h"
 #include "i18n.h"
+#include "fltk_layout.h"
 #include "parameters.h"
 #include "keysym2ucs.h"
 
@@ -575,6 +576,7 @@
 void Viewport::popupContextMenu()
 {
   const Fl_Menu_Item *m;
+  char buffer[1024];
 
   contextMenu->position(Fl::event_x(), Fl::event_y());
 
@@ -618,8 +620,10 @@
     OptionsDialog::showDialog();
     break;
   case ID_INFO:
-    fl_message_title(_("VNC connection info"));
-    fl_message(cc->connectionInfo());
+    if (fltk_escape(cc->connectionInfo(), buffer, sizeof(buffer)) < 
sizeof(buffer)) {
+      fl_message_title(_("VNC connection info"));
+      fl_message(buffer);
+    }
     break;
   case ID_ABOUT:
     about_vncviewer();

Modified: trunk/vncviewer/fltk_layout.h
===================================================================
--- trunk/vncviewer/fltk_layout.h       2011-05-23 11:21:22 UTC (rev 4439)
+++ trunk/vncviewer/fltk_layout.h       2011-05-23 12:21:21 UTC (rev 4440)
@@ -33,6 +33,40 @@
     return (int)(len + 0.5f);
 }
 
+/* Escapes all @ in text as those have special meaning in labels */
+static inline int fltk_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;
+}
+
 /**** MARGINS ****/
 
 #define OUTER_MARGIN            10


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Tigervnc-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits

Reply via email to