Menu

#49 Bad example given in "Getting started"

open
nobody
None
5
2008-11-05
2008-11-05
No

In "Evaluating a Tcl command from Java" the following code written:

interp.eval("string length \"" + thestr + "\"");

It is very bad because if thestr="str\";bad_command" will cause error 'invalid command name "bad_command"'.

The right code are the following:

interp.setVar("s", TclString.newInstance(thestr), 0);
interp.eval("string length $s");

Discussion


Log in to post a comment.