summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tclStringObj.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 4af164c..41ecf137 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -33,7 +33,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStringObj.c,v 1.28 2003/01/24 11:59:29 vincentdarley Exp $ */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.29 2003/02/11 18:35:11 hobbs Exp $ */
#include "tclInt.h"
@@ -376,7 +376,7 @@ Tcl_GetCharLength(objPtr)
*/
if (stringPtr->numChars == -1) {
- register int i = 0;
+ register int i = 0, len = objPtr->length;
register unsigned char *str = (unsigned char *) objPtr->bytes;
/*
@@ -386,14 +386,13 @@ Tcl_GetCharLength(objPtr)
stringPtr->numChars = Tcl_NumUtfChars(objPtr->bytes, objPtr->length);
*/
- while (*str && *str < 0xC0) { i++; str++; }
+ while ((i < len) && (*str < 0xC0)) { i++; str++; }
stringPtr->numChars = i;
- if (*str) {
- stringPtr->numChars += Tcl_NumUtfChars(objPtr->bytes + i,
- objPtr->length - i);
+ if (i < len) {
+ stringPtr->numChars += Tcl_NumUtfChars(objPtr->bytes + i, len - i);
}
- if (stringPtr->numChars == objPtr->length) {
+ if (stringPtr->numChars == len) {
/*
* Since we've just calculated the number of chars, and all