keycmd_bs: fix invalid utf-8 char chopping code
authorkmeaw <kmeaw@flib.ru>
Thu, 11 Jun 2009 09:11:57 +0000 (13:11 +0400)
committerkmeaw <kmeaw@flib.ru>
Thu, 11 Jun 2009 09:11:57 +0000 (13:11 +0400)
This code failed on strings that end on a multibyte character.

uzbl.c

diff --git a/uzbl.c b/uzbl.c
index f1c27b1..6c99db8 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
@@ -883,9 +883,12 @@ keycmd_nl (WebKitWebView *page, GArray *argv) {
 
 static void
 keycmd_bs (WebKitWebView *page, GArray *argv) {
+    gchar *prev;
     (void)page;
     (void)argv;
-    g_string_truncate(uzbl.state.keycmd, uzbl.state.keycmd->len - 1);
+    prev = g_utf8_find_prev_char(uzbl.state.keycmd->str, uzbl.state.keycmd->str + uzbl.state.keycmd->len);
+    if (prev)
+      g_string_truncate(uzbl.state.keycmd, prev - uzbl.state.keycmd->str);
     update_title();
 }