[910] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r896 - branches/barnowl_unicode/owl

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:11:02 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Thu, 17 Jan 2008 14:55:23 -0500 (EST)

Author: asedeno
Date: 2008-01-17 14:55:22 -0500 (Thu, 17 Jan 2008)
New Revision: 896

Modified:
   branches/barnowl_unicode/owl/owl.c
Log:
unicode/glib branch
better compliance with UTF-8 processing. Stop trying to pull in a UTF-8
character as soon as we know something has gone wrong.

Modified: branches/barnowl_unicode/owl/owl.c
===================================================================
--- branches/barnowl_unicode/owl/owl.c	2008-01-17 14:51:48 UTC (rev 895)
+++ branches/barnowl_unicode/owl/owl.c	2008-01-17 19:55:22 UTC (rev 896)
@@ -561,14 +561,26 @@
 	else bytes = 1;
 	
 	for (i = 1; i < bytes; i++) {
-	  utf8buf[i] = wgetch(typwin);
-	}
-	if (g_utf8_validate(utf8buf, -1, NULL)) {
-	  j.uch = g_utf8_get_char(utf8buf);
-	}
-	else {
-	  j.ch = ERR;
-	}
+          int tmp =  wgetch(typwin);
+          /* If what we got was not a byte, or not a continuation byte */
+          if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) {
+            /* ill-formed UTF-8 code unit subsequence, put back the
+               char we just got. */
+            ungetch(tmp);
+            j.ch = ERR;
+            break;
+          }
+	  utf8buf[i] = tmp;
+        }
+        
+	if (j.ch != ERR) {
+          if (g_utf8_validate(utf8buf, -1, NULL)) {
+            j.uch = g_utf8_get_char(utf8buf);
+          }
+          else {
+            j.ch = ERR;
+          }
+        }
       }
       else if (j.ch <= 0x7f) {
 	j.uch = j.ch;


home help back first fref pref prev next nref lref last post