From 5ca4f427ac2f26f0dd3aa77294b8c80ed44df14b Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 23 Dec 2014 17:26:07 +0000 Subject: Support TCL_ENCODING_CHAR_LIMIT in the UtfToUtfProc driver. --- generic/tclEncoding.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 5c5254b..f92cabb 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -2294,7 +2294,7 @@ UtfToUtfProc( { const char *srcStart, *srcEnd, *srcClose; const char *dstStart, *dstEnd; - int result, numChars; + int result, numChars, charLimit = INT_MAX; Tcl_UniChar ch; result = TCL_OK; @@ -2305,11 +2305,14 @@ UtfToUtfProc( if ((flags & TCL_ENCODING_END) == 0) { srcClose -= TCL_UTF_MAX; } + if (flags & TCL_ENCODING_CHAR_LIMIT) { + charLimit = *dstCharsPtr; + } dstStart = dst; dstEnd = dst + dstLen - TCL_UTF_MAX; - for (numChars = 0; src < srcEnd; numChars++) { + for (numChars = 0; src < srcEnd && numChars <= charLimit; numChars++) { if ((src > srcClose) && (!Tcl_UtfCharComplete(src, srcEnd - src))) { /* * If there is more string to follow, this will ensure that the -- cgit v0.12