Reputation: 3235
In my C side implementation of a TCL command, say, in following signature:
myfunc(ClientData c, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[]);
I found that sometimes objc is larger than the number of arguments passed in, and the corresponding objv value is either "0" or "1".
I cannot find any reporting such issue in googling, should be somewhere wrong in my TCL side, but could not figure out how come.
My TCL side calling the command either with 2 arguments or 3 arguments -
myfunc arg1 "word1 word2"
<... some code ...>
myfunc arg1 "" "checker1 checker2"
The first call is 2 arguments and next 3 arguments.
The problem I mentioned is when I expect 2 arguments, I see "objc" is 3 and "objv[3]" is either "0" or "1".
Upvotes: 1
Views: 100
Reputation: 47680
I don't know if that's your issue (it could be a typo) but objv[3] is access to out of bounds when objc is only 3, because when count is 3, maximum accessible index is 2. You should be starting at objv[0] to access array contents.
Upvotes: 1