L
linq936
Hi,
My program crashes on Linux64 platform. The crash only happens on
optimized compiling, if I compile the code in debug mode, it works
fine. If I compile the code on Linux 32 platform, neither debug mode
nor optimized mode crashes.
In tracking the issue, I finally narrow the code into something like
this:
int my_func(ClientData client_data,
Tcl_Interp* interp,
Tcl_Obj* CONST argv[]) {
< some code >
MyClass* myobj;
Tcl_GetIntFromObj(interp, argv[1], (int *) &myobj);
You can see this is to interact with TCL through C/TCL interface,
you can also see that myobj is not initialized before used.
I tested changing the code to:
MyClass* myobj = NULL;
Tcl_GetIntFromObj(interp, argv[1], (int *) &myobj);
Now it works.
But this does not make sense to me. I check into TCL 8.4 source code
for this function, Tcl_GetIntFromObj(), the simplified version is like
this,
int
Tcl_GetIntFromObj(interp, objPtr, intPtr)
Tcl_Interp *interp; /* Used for error reporting if not NULL. */
register Tcl_Obj *objPtr; /* The object from which to get a int.
*/
register int *intPtr; /* Place to store resulting int. */
{
< some code>
*intPtr = (int)w; <=== This is the only place intPtr is used
return TCL_OK;
}
I do not see why my change, give myobj an initial assignment, could
make difference upon this TCL code except the following 2
obsersavations:
1. If I do not assign myobj to NULL, compiler may give it a wild
address which in optimized mode always points to some not-allowed
address?
2. The TCL function declares the argument as "register int *intPtr",
I never use "register" keyword in my C programming, not sure if it has
a role over here.
Would really appreciate if you could shed some light here.
My program crashes on Linux64 platform. The crash only happens on
optimized compiling, if I compile the code in debug mode, it works
fine. If I compile the code on Linux 32 platform, neither debug mode
nor optimized mode crashes.
In tracking the issue, I finally narrow the code into something like
this:
int my_func(ClientData client_data,
Tcl_Interp* interp,
Tcl_Obj* CONST argv[]) {
< some code >
MyClass* myobj;
Tcl_GetIntFromObj(interp, argv[1], (int *) &myobj);
You can see this is to interact with TCL through C/TCL interface,
you can also see that myobj is not initialized before used.
I tested changing the code to:
MyClass* myobj = NULL;
Tcl_GetIntFromObj(interp, argv[1], (int *) &myobj);
Now it works.
But this does not make sense to me. I check into TCL 8.4 source code
for this function, Tcl_GetIntFromObj(), the simplified version is like
this,
int
Tcl_GetIntFromObj(interp, objPtr, intPtr)
Tcl_Interp *interp; /* Used for error reporting if not NULL. */
register Tcl_Obj *objPtr; /* The object from which to get a int.
*/
register int *intPtr; /* Place to store resulting int. */
{
< some code>
*intPtr = (int)w; <=== This is the only place intPtr is used
return TCL_OK;
}
I do not see why my change, give myobj an initial assignment, could
make difference upon this TCL code except the following 2
obsersavations:
1. If I do not assign myobj to NULL, compiler may give it a wild
address which in optimized mode always points to some not-allowed
address?
2. The TCL function declares the argument as "register int *intPtr",
I never use "register" keyword in my C programming, not sure if it has
a role over here.
Would really appreciate if you could shed some light here.