summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-09-07 14:35:56 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-09-07 14:35:56 (GMT)
commit2d710b7bfb946720a165117b51982657462c87c2 (patch)
tree2a4e216e11cb2db2b5630d29d69d06832126d343 /generic
parentf1fab031095240c82752590963ffa7bbeca994fa (diff)
downloadtcl-2d710b7bfb946720a165117b51982657462c87c2.zip
tcl-2d710b7bfb946720a165117b51982657462c87c2.tar.gz
tcl-2d710b7bfb946720a165117b51982657462c87c2.tar.bz2
* generic/tclUtf.c (Tcl_UniCharToUtf): Corrected handling of negative
* tests/utf.test (utf-1.5): Tcl_UniChar input value. Incorrect handling was producing byte sequences outside of Tcl's legal internal encoding. [Bug 1283976].
Diffstat (limited to 'generic')
-rw-r--r--generic/tclUtf.c74
1 files changed, 38 insertions, 36 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c
index b7a6277..923f49f 100644
--- a/generic/tclUtf.c
+++ b/generic/tclUtf.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUtf.c,v 1.30.2.2 2003/10/08 14:21:20 dkf Exp $
+ * RCS: @(#) $Id: tclUtf.c,v 1.30.2.3 2005/09/07 14:35:56 dgp Exp $
*/
#include "tclInt.h"
@@ -169,45 +169,47 @@ Tcl_UniCharToUtf(ch, str)
str[0] = (char) ch;
return 1;
}
- if (ch <= 0x7FF) {
- str[1] = (char) ((ch | 0x80) & 0xBF);
- str[0] = (char) ((ch >> 6) | 0xC0);
- return 2;
- }
- if (ch <= 0xFFFF) {
+ if (ch >= 0) {
+ if (ch <= 0x7FF) {
+ str[1] = (char) ((ch | 0x80) & 0xBF);
+ str[0] = (char) ((ch >> 6) | 0xC0);
+ return 2;
+ }
+ if (ch <= 0xFFFF) {
three:
- str[2] = (char) ((ch | 0x80) & 0xBF);
- str[1] = (char) (((ch >> 6) | 0x80) & 0xBF);
- str[0] = (char) ((ch >> 12) | 0xE0);
- return 3;
- }
+ str[2] = (char) ((ch | 0x80) & 0xBF);
+ str[1] = (char) (((ch >> 6) | 0x80) & 0xBF);
+ str[0] = (char) ((ch >> 12) | 0xE0);
+ return 3;
+ }
#if TCL_UTF_MAX > 3
- if (ch <= 0x1FFFFF) {
- str[3] = (char) ((ch | 0x80) & 0xBF);
- str[2] = (char) (((ch >> 6) | 0x80) & 0xBF);
- str[1] = (char) (((ch >> 12) | 0x80) & 0xBF);
- str[0] = (char) ((ch >> 18) | 0xF0);
- return 4;
- }
- if (ch <= 0x3FFFFFF) {
- str[4] = (char) ((ch | 0x80) & 0xBF);
- str[3] = (char) (((ch >> 6) | 0x80) & 0xBF);
- str[2] = (char) (((ch >> 12) | 0x80) & 0xBF);
- str[1] = (char) (((ch >> 18) | 0x80) & 0xBF);
- str[0] = (char) ((ch >> 24) | 0xF8);
- return 5;
- }
- if (ch <= 0x7FFFFFFF) {
- str[5] = (char) ((ch | 0x80) & 0xBF);
- str[4] = (char) (((ch >> 6) | 0x80) & 0xBF);
- str[3] = (char) (((ch >> 12) | 0x80) & 0xBF);
- str[2] = (char) (((ch >> 18) | 0x80) & 0xBF);
- str[1] = (char) (((ch >> 24) | 0x80) & 0xBF);
- str[0] = (char) ((ch >> 30) | 0xFC);
- return 6;
- }
+ if (ch <= 0x1FFFFF) {
+ str[3] = (char) ((ch | 0x80) & 0xBF);
+ str[2] = (char) (((ch >> 6) | 0x80) & 0xBF);
+ str[1] = (char) (((ch >> 12) | 0x80) & 0xBF);
+ str[0] = (char) ((ch >> 18) | 0xF0);
+ return 4;
+ }
+ if (ch <= 0x3FFFFFF) {
+ str[4] = (char) ((ch | 0x80) & 0xBF);
+ str[3] = (char) (((ch >> 6) | 0x80) & 0xBF);
+ str[2] = (char) (((ch >> 12) | 0x80) & 0xBF);
+ str[1] = (char) (((ch >> 18) | 0x80) & 0xBF);
+ str[0] = (char) ((ch >> 24) | 0xF8);
+ return 5;
+ }
+ if (ch <= 0x7FFFFFFF) {
+ str[5] = (char) ((ch | 0x80) & 0xBF);
+ str[4] = (char) (((ch >> 6) | 0x80) & 0xBF);
+ str[3] = (char) (((ch >> 12) | 0x80) & 0xBF);
+ str[2] = (char) (((ch >> 18) | 0x80) & 0xBF);
+ str[1] = (char) (((ch >> 24) | 0x80) & 0xBF);
+ str[0] = (char) ((ch >> 30) | 0xFC);
+ return 6;
+ }
#endif
+ }
ch = 0xFFFD;
goto three;