Re: Tcl_SetStringObj question
- From: fredericbonnet@xxxxxxx
- Date: Mon, 28 Jul 2008 09:22:44 -0700 (PDT)
The source of the problem is here:
Tcl_SetStringObj(resultPtr, myname, sizeof(myname));^^^^^^^^^^^^^^
If myname is a static or stack-allocated buffer (which is most likely
the case, as I see no free()), sizeof() returns its size in bytes,
which will exceed the actual length of the string. So the created
Tcl_Obj will have a string rep that starts with the given string but
extends past the NUL terminator up to the end of the buffer. This
string will not be equal to the plain string "NULL", hence your
problem.
The code should be:
Tcl_SetStringObj(resultPtr, myname, strlen(myname));
or:
Tcl_SetStringObj(resultPtr, myname, -1);
for an implied strlen.
.
- Follow-Ups:
- Re: Tcl_SetStringObj question
- From: icanbob
- Re: Tcl_SetStringObj question
- References:
- Tcl_SetStringObj question
- From: icanbob
- Tcl_SetStringObj question
- Prev by Date: Tcl_SetStringObj question
- Next by Date: Re: Guys, Do you have a plan to integrate the telnet extention in Tcl built commands?
- Previous by thread: Tcl_SetStringObj question
- Next by thread: Re: Tcl_SetStringObj question
- Index(es):
Relevant Pages
|