Posted to tcl by xharx at Thu Nov 12 16:30:36 GMT 2020view pretty

int EPtkcreatepicdata(ClientData clientdata, Tcl_Interp *interp, int arc, const char **argv) {
	char *pto=malloc(100);
	sprintf(pto, "%s", "dings");
	Tcl_Obj *mobj=Tcl_NewObj();
	mobj->bytes=pto;
	mobj->length=10;
	Tcl_SetObjResult(interp, mobj);
	return TCL_OK;
}

void registercommands(Tcl_Interp *tcl_interp) {
	Tcl_CreateCommand(tcl_interp, "epcreatepicdata", EPtkcreatepicdata, (ClientData) NULL, (Tcl_CmdDeleteProc *)NULL);

}

Now, in a tcl- script, when I say eg.
puts [epcreatepicdata]
I get a
dings
alloc: invalid block: 0x7f8f8c3dcf70: a5 0
What do I do wrong?