Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/nvi/dist/common Restore the initial state at th...
details: https://anonhg.NetBSD.org/src/rev/dc76ab479588
branches: trunk
changeset: 357434:dc76ab479588
user: rin <rin%NetBSD.org@localhost>
date: Fri Nov 10 18:08:11 2017 +0000
description:
Restore the initial state at the end of line.
This matters for stateful encodings like iso-2022-jp.
Fix taken from yamt via nvi2.
diffstat:
external/bsd/nvi/dist/common/conv.c | 24 +++++++++++++-----------
1 files changed, 13 insertions(+), 11 deletions(-)
diffs (71 lines):
diff -r 3f489cbbfce5 -r dc76ab479588 external/bsd/nvi/dist/common/conv.c
--- a/external/bsd/nvi/dist/common/conv.c Fri Nov 10 17:31:12 2017 +0000
+++ b/external/bsd/nvi/dist/common/conv.c Fri Nov 10 18:08:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conv.c,v 1.5 2017/11/06 03:02:22 rin Exp $ */
+/* $NetBSD: conv.c,v 1.6 2017/11/10 18:08:11 rin Exp $ */
/*-
* Copyright (c) 1993, 1994
* The Regents of the University of California. All rights reserved.
@@ -16,7 +16,7 @@
static const char sccsid[] = "Id: conv.c,v 1.27 2001/08/18 21:41:41 skimo Exp (Berkeley) Date: 2001/08/18 21:41:41 ";
#endif /* not lint */
#else
-__RCSID("$NetBSD: conv.c,v 1.5 2017/11/06 03:02:22 rin Exp $");
+__RCSID("$NetBSD: conv.c,v 1.6 2017/11/10 18:08:11 rin Exp $");
#endif
#include <sys/types.h>
@@ -260,10 +260,11 @@
* cw->bp is grown as required
*/
#ifdef USE_ICONV
-#define CONVERT2(len, cw, offset) \
+#define CONVERT2(_buffer, lenp, cw, offset) \
do { \
- const char *bp = buffer; \
- while (len != 0) { \
+ const char *bp = _buffer; \
+ size_t ret; \
+ do { \
size_t outleft = cw->blen1 - offset; \
char *obp = (char *)cw->bp1 + offset; \
if (cw->blen1 < offset + MB_CUR_MAX) { \
@@ -271,14 +272,14 @@
BINC_RETC(NULL, cw->bp1, cw->blen1, nlen); \
} \
errno = 0; \
- if (iconv(id, &bp, &len, &obp, &outleft) == (size_t)-1 && \
- errno != E2BIG) \
+ ret = iconv(id, &bp, lenp, &obp, &outleft); \
+ if (ret == (size_t)-1 && errno != E2BIG) \
HANDLE_ICONV_ERROR(obp, bp, outleft, len); \
offset = cw->blen1 - outleft; \
- } \
+ } while (ret != 0); \
} while (0)
#else
-#define CONVERT2(len, cw, offset)
+#define CONVERT2(_buffer, lenp, cw, offset)
#endif
@@ -304,7 +305,7 @@
j += n;
if (buflen < j + MB_CUR_MAX) {
if (id != (iconv_t)-1) {
- CONVERT2(j, cw, offset);
+ CONVERT2(buffer, &j, cw, offset);
} else {
nlen += 256;
BINC_RETC(NULL, *tostr, *blen, nlen);
@@ -318,7 +319,8 @@
*tolen = j;
if (id != (iconv_t)-1) {
- CONVERT2(j, cw, offset);
+ CONVERT2(buffer, &j, cw, offset);
+ CONVERT2(NULL, NULL, cw, offset); /* back to the initial state */
*tolen = offset;
}
Home |
Main Index |
Thread Index |
Old Index