Index: /branches/working-0711/ccl/level-0/l0-io.lisp
===================================================================
--- /branches/working-0711/ccl/level-0/l0-io.lisp	(revision 9627)
+++ /branches/working-0711/ccl/level-0/l0-io.lisp	(revision 9628)
@@ -81,5 +81,5 @@
                    (logior #x80 (the fixnum (logand #x3f (the fixnum (ash code -6))))))
              (setf (%get-unsigned-byte pointer (the fixnum (+ idx 3)))
-                   (logand #x3f code))
+                   (logior #x80 (logand #x3f code)))
              (incf idx 4))))))
 
@@ -147,13 +147,14 @@
         (end (+ start noctets))
         (nchars 0 (1+ nchars)))
-       ((= i end) (values nchars i))
+       ((= i end) (values nchars (- i start)))
     (let* ((code (%get-unsigned-byte pointer i))
-           (nexti (+ i (cond ((< code #x80) 1)
+           (nexti (+ i (cond ((< code #xc2) 1)
                              ((< code #xe0) 2)
                              ((< code #xf0) 3)
-                             (t 4)))))
+                             ((< code #xf8) 4)
+                             (t 1)))))
       (declare (type (unsigned-byte 8) code))
       (if (> nexti end)
-        (return (values nchars i))
+        (return (values nchars (- i start)))
         (setq i nexti)))))
 
