Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1057 Tcl_SetUnicodeObj(objPtr, unicode, numChars) fails if numCha

obsolete: 8.2.1
closed-fixed
nobody
2
2000-10-26
2000-10-26
Anonymous
No

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

Discussion

  • Brent B. Welch
    Brent B. Welch
    2000-10-26

    • priority: 5 --> 2
    • status: open --> closed-fixed