[vte] debug: Fix printing the sequence string



commit b941987a7060662de320e76cda05f08dde5e10aa
Author: Christian Persch <chpe src gnome org>
Date:   Tue Oct 24 18:38:58 2017 +0200

    debug: Fix printing the sequence string
    
    Add a length parameter for non-0-terminated strings, and use it.

 src/debug.c   |   14 ++++++++++----
 src/debug.h   |    3 ++-
 src/keymap.cc |    2 +-
 src/table.cc  |    8 +++++---
 4 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/src/debug.c b/src/debug.c
index 6fc9648..132e805 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -16,7 +16,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <config.h>
+#include "config.h"
+
+#include <string.h>
 
 #include <glib.h>
 #include "debug.h"
@@ -63,7 +65,8 @@ _vte_debug_init(void)
 }
 
 const char *
-_vte_debug_sequence_to_string(const char *str)
+_vte_debug_sequence_to_string(const char *str,
+                              gssize length)
 {
 #if defined(VTE_DEBUG)
         static const char codes[][6] = {
@@ -74,16 +77,19 @@ _vte_debug_sequence_to_string(const char *str)
                 "SPACE"
         };
         static GString *buf;
-        int i;
+        gssize i;
 
         if (str == NULL)
                 return "(nil)";
 
+        if (length == -1)
+                length = strlen(str);
+
         if (buf == NULL)
                 buf = g_string_new(NULL);
 
         g_string_truncate(buf, 0);
-        for (i = 0; str[i]; i++) {
+        for (i = 0; i < length; i++) {
                 guint8 c = (guint8)str[i];
                 if (i > 0)
                         g_string_append_c(buf, ' ');
diff --git a/src/debug.h b/src/debug.h
index a1622e4..260d6dc 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -66,7 +66,8 @@ typedef enum {
 } VteDebugFlags;
 
 void _vte_debug_init(void);
-const char *_vte_debug_sequence_to_string(const char *str);
+const char *_vte_debug_sequence_to_string(const char *str,
+                                          gssize length);
 
 extern guint _vte_debug_flags;
 static inline gboolean _vte_debug_on(guint flags) G_GNUC_CONST G_GNUC_UNUSED;
diff --git a/src/keymap.cc b/src/keymap.cc
index 1874368..b8e02f1 100644
--- a/src/keymap.cc
+++ b/src/keymap.cc
@@ -770,7 +770,7 @@ _vte_keymap_map(guint keyval,
                                                   normal_length);
                 _vte_debug_print(VTE_DEBUG_KEYBOARD,
                                  " to '%s'.\n",
-                                 _vte_debug_sequence_to_string(*normal));
+                                 _vte_debug_sequence_to_string(*normal, -1));
                 return;
        }
 
diff --git a/src/table.cc b/src/table.cc
index 85fa676..9484983 100644
--- a/src/table.cc
+++ b/src/table.cc
@@ -208,11 +208,13 @@ _vte_table_addi(struct _vte_table *table,
        if (length == 0) {
                if (table->result != NULL)
                         _VTE_DEBUG_IF (VTE_DEBUG_PARSE) {
-                                g_printerr ("'%s'=> '%s'",
-                                            _vte_debug_sequence_to_string ((const char *)table->original),
+                                g_printerr ("'%s' => '%s'",
+                                            _vte_debug_sequence_to_string ((const char *)table->original,
+                                                                           table->original_length),
                                             table->result);
                                 g_printerr (" and '%s' => '%s' are indistinguisable.\n",
-                                            _vte_debug_sequence_to_string ((const char *)original),
+                                            _vte_debug_sequence_to_string ((const char *)original,
+                                                                           original_length),
                                             result);
                         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]