summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2023-03-06 20:34:36 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2023-03-06 20:34:36 +0000
commitf846a7cfac6d480e0c80149b9be3733040b51a53 (patch)
tree2b535b76d5fa10ca7e5d893808b31e77289d713c /sys
parent0a73619d2f995b681b09bf3d87ad90a1cab4ef6b (diff)
Correctly account the number of bytes processed when outputting UTF-8 encoded
characters.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/wscons/wsemul_sun.c18
-rw-r--r--sys/dev/wscons/wsemul_vt100.c19
2 files changed, 20 insertions, 17 deletions
diff --git a/sys/dev/wscons/wsemul_sun.c b/sys/dev/wscons/wsemul_sun.c
index c866b11eed7..40871af462b 100644
--- a/sys/dev/wscons/wsemul_sun.c
+++ b/sys/dev/wscons/wsemul_sun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsemul_sun.c,v 1.35 2023/03/06 17:14:44 miod Exp $ */
+/* $OpenBSD: wsemul_sun.c,v 1.36 2023/03/06 20:34:35 miod Exp $ */
/* $NetBSD: wsemul_sun.c,v 1.11 2000/01/05 11:19:36 drochner Exp $ */
/*
@@ -662,7 +662,7 @@ wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
{
struct wsemul_sun_emuldata *edp = cookie;
struct wsemul_inputstate *instate;
- u_int processed = 0;
+ u_int prev_count, processed = 0;
#ifdef HAVE_JUMP_SCROLL
int lines;
#endif
@@ -679,7 +679,7 @@ wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
case ABORT_FAILED_CURSOR:
/*
* If we could not display the cursor back, we pretended not
- * having been able to display the last character. But this
+ * having been able to process the last byte. But this
* is a lie, so compensate here.
*/
data++, count--;
@@ -746,6 +746,7 @@ wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
wsemul_resume_abort(&edp->abortstate);
+ prev_count = count;
if (wsemul_getchar(&data, &count, instate,
#ifdef HAVE_UTF8_SUPPORT
(edp->state == SUN_EMUL_STATE_NORMAL && !kernel) ?
@@ -760,7 +761,7 @@ wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
rc = wsemul_sun_output_lowchars(edp, instate, kernel);
if (rc != 0)
break;
- processed++;
+ processed += prev_count - count;
continue;
}
@@ -768,7 +769,7 @@ wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
rc = wsemul_sun_output_normal(edp, instate, 1);
if (rc != 0)
break;
- processed++;
+ processed += prev_count - count;
continue;
}
@@ -799,7 +800,7 @@ wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
}
if (rc != 0)
break;
- processed++;
+ processed += prev_count - count;
}
if (rc != 0)
@@ -810,8 +811,9 @@ wsemul_sun_output(void *cookie, const u_char *data, u_int count, int kernel)
(edp->emulcookie, 1, edp->crow, edp->ccol);
if (rc != 0) {
/*
- * Fail the last character output, remembering that
- * only the cursor operation really needs to be done.
+ * Pretend the last byte hasn't been processed, while
+ * remembering that only the cursor operation really
+ * needs to be done.
*/
wsemul_abort_cursor(&edp->abortstate);
processed--;
diff --git a/sys/dev/wscons/wsemul_vt100.c b/sys/dev/wscons/wsemul_vt100.c
index b58f2237dd8..1f976bd8231 100644
--- a/sys/dev/wscons/wsemul_vt100.c
+++ b/sys/dev/wscons/wsemul_vt100.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsemul_vt100.c,v 1.44 2023/03/06 17:14:44 miod Exp $ */
+/* $OpenBSD: wsemul_vt100.c,v 1.45 2023/03/06 20:34:35 miod Exp $ */
/* $NetBSD: wsemul_vt100.c,v 1.13 2000/04/28 21:56:16 mycroft Exp $ */
/*
@@ -1110,7 +1110,7 @@ wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
{
struct wsemul_vt100_emuldata *edp = cookie;
struct wsemul_inputstate *instate;
- u_int processed = 0;
+ u_int prev_count, processed = 0;
#ifdef HAVE_JUMP_SCROLL
int lines;
#endif
@@ -1127,7 +1127,7 @@ wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
case ABORT_FAILED_CURSOR:
/*
* If we could not display the cursor back, we pretended not
- * having been able to display the last character. But this
+ * having been able to process the last byte. But this
* is a lie, so compensate here.
*/
data++, count--;
@@ -1200,6 +1200,7 @@ wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
wsemul_resume_abort(&edp->abortstate);
+ prev_count = count;
if (wsemul_getchar(&data, &count, instate,
#ifdef HAVE_UTF8_SUPPORT
(edp->state == VT100_EMUL_STATE_NORMAL && !kernel) ?
@@ -1215,7 +1216,7 @@ wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
rc = wsemul_vt100_output_c0c1(edp, instate, kernel);
if (rc != 0)
break;
- processed++;
+ processed += prev_count - count;
continue;
}
@@ -1223,7 +1224,7 @@ wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
rc = wsemul_vt100_output_normal(edp, instate, kernel);
if (rc != 0)
break;
- processed++;
+ processed += prev_count - count;
continue;
}
#ifdef DIAGNOSTIC
@@ -1233,7 +1234,7 @@ wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
rc = vt100_output[edp->state - 1](edp, instate);
if (rc != 0)
break;
- processed++;
+ processed += prev_count - count;
}
if (rc != 0)
@@ -1250,9 +1251,9 @@ wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
#endif
if (rc != 0) {
/*
- * Fail the last character output, remembering
- * that only the cursor operation really needs
- * to be done.
+ * Pretend the last byte hasn't been processed,
+ * while remembering that only the cursor
+ * operation really needs to be done.
*/
wsemul_abort_cursor(&edp->abortstate);
processed--;