Bug in append
Closed / Fixed218911ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:07:47
OriginalBugID: 2678 Bug
Version: 8.2
SubmitDate: '1999-08-31'
LastModified: '1999-09-01'
Severity: LOW
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: Other
Machine: NA
FixedDate: '1999-09-01'
ClosedDate: '2000-10-25'
Name:
Peter Spjuth
ReproducibleScript:
# s1 is a string with "normal" chars
set s1 gurka
# Give it an internal string rep.
string length $s1
# s1 contains unicode char
set s2 måla
string length $s2
append s1 $s2
# After the append, the internal string object erroneously is set up
# as a one-byte-per-char string. String index uses this and indexes
# directly, and misses one step.
puts "This: '[string index $s1 8]', should be an 'a'."
ObservedBehavior:
Append messes up the string object and causes string index to give the
wrong answer.
The bug is in Tcl_AppendObjToObj which does not check uallocated when it
tries
to determine if the appended string is one-byte-per-char.
Patch:
Index: tclStringObj.c
===================================================================
RCS file: /cvsroot/tcl/generic/tclStringObj.c,v
retrieving revision 1.12
diff -c -r1.12 tclStringObj.c
*** tclStringObj.c1999/06/16 00:47:561.12
--- tclStringObj.c1999/08/31 18:11:05
***************
*** 920,926 ****
numChars = stringPtr->numChars;
if ((numChars >= 0) && (appendObjPtr->typePtr == &tclStringType)) {
stringPtr = GET_STRING(appendObjPtr);
! if (stringPtr->numChars >= 0) {
numChars += stringPtr->numChars;
allOneByteChars = 1;
}
--- 920,926 ----
numChars = stringPtr->numChars;
if ((numChars >= 0) && (appendObjPtr->typePtr == &tclStringType)) {
stringPtr = GET_STRING(appendObjPtr);
! if (stringPtr->numChars >= 0 && stringPtr->uallocated == 0) {
numChars += stringPtr->numChars;
allOneByteChars = 1;
}
PatchFiles:
tclStringObj.c
Confirmed and fixed for 8.2.1.
-- 09/01/1999 hobbs
welch Closed ticket [218911ffff].
[History diff]2000-10-26 08:31:16
dgp Ticket [218911ffff]: 1 change
[History diff]2001-04-19 03:15:03
dgp Ticket [218911ffff]: 2 changes
[History diff]2001-04-19 03:15:04
Log in (anonymous is fine) to add a comment.