Tcl Source Code

View Ticket
Login
EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA
2000-10-26
08:32 Closed ticket [218974ffff]: Tcl_SetUnicodeObj(objPtr, unicode, numChars) fails if numCha plus 4 other changes artifact: 31f9201ea0 user: welch
01:08 New ticket [218974ffff]. artifact: aef7fcad6a user: nobody

Ticket UUID: 218974
Title: Tcl_SetUnicodeObj(objPtr, unicode, numChars) fails if numCha
Type: Bug Version: obsolete: 8.2.1
Submitter: nobody Created on: 2000-10-26 01:08:50
Subsystem: 10. Objects Assigned To: nobody
Priority: 2 Severity:
Status: Closed Last Modified: 2000-10-26 08:32:16
Resolution: Fixed Closed By: welch
    Closed on: 2000-10-26 01:32:16
Description:
OriginalBugID: 3380 Bug
Version: 8.2.1
SubmitDate: '1999-11-05'
LastModified: '1999-11-11'
Severity: MED
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: Windows NT
OSVersion: 4.0 sp4
FixedDate: '1999-11-11'
FixedInVersion: 8.2.3
ClosedDate: '2000-10-25'


Name: Martin Grosz

Comments:
I am using Windows NT & VC++ 6.0 & SWIG.
    My code is in a 'load'ed .dll

ReproducibleScript:
Create a unicode string:
    Tcl_UniChar * unicode = L"my unic string";
    
    Get an object pointer.
    tcl_result = Tcl_GetObjResult(interp);
    
    Make the call:
    Tcl_SetUnicodeObj( tcl_result, _result, -1 );
    
    results in a memory access error trying to read invalid address in
    memcpy.
    
    Using this call instead works:
    Tcl_SetUnicodeObj( tcl_result, _result, ::wcslen(_result) );
    
    Documentation says:
    "int numChars (in) The number of Unicode characters to copy from unicode
    when initializing, setting, or appending to a string object. If
    negative, all characters up to the first null character are used."
    WRONG!!!

ObservedBehavior:
Unhandled exception in tclsh82.exe (MSVCRTD.DLL): 0xC0000005: Access
    Violation
    
    stack
    
    memcpy(unsigned char * 0x00333fac, unsigned char * 0x011f2e40, unsigned
    long 0xfffffffe) line 171
    Tcl_SetUnicodeObj(Tcl_Obj * 0x0029f950, unsigned short * 0x011f2e40, int
    0xffffffff) line 727 + 22 bytes
    _wrap_ComputerNameGet(void * 0x00000000, Tcl_Interp * 0x002b2d28, int
    0x00000001, Tcl_Obj * const * 0x002db5e8) line 1939 + 18 bytes
    TclExecuteByteCode(Tcl_Interp * 0x002b2d28, ByteCode * 0x002c6388) line
    844 + 25 bytes
    Tcl_EvalObjEx(Tcl_Interp * 0x002b2d28, Tcl_Obj * 0x0029eaa0, int
    0x00000000) line 2698 + 13 bytes
    Tcl_RecordAndEvalObj(Tcl_Interp * 0x002b2d28, Tcl_Obj * 0x0029eaa0, int
    0x00000000) line 142 + 23 bytes
    Tcl_Main(int 0x00000001, char * * 0x00283488, int (Tcl_Interp *)*
    0x0040103d Tcl_AppInit(Tcl_Interp *)) line 236 + 21 bytes
    main() line 64 + 19 bytes
    mainCRTStartup() line 338 + 17 bytes
    KERNEL32! 77f1ba3c()

DesiredBehavior:
Documentation says:
    "int numChars (in) The number of Unicode characters to copy from unicode
    when initializing, setting, or appending to a string object. If
    negative, all characters up to the first null character are used."



Somehow the whole UnicodeObj set of functions missed the
handling of numChars < 0. 
-- 11/11/1999 hobbs
The correct checks were added to Tcl_(New|Set)UnicodeObj
and the private funcs that Tcl_AppendUnicodeToObj calls. 
-- 11/11/1999 hobbs