Tcl Source Code

View Ticket
Login
2026-10-21
09:58 • Closed ticket [ece07271f4]: Bug in Tcl_ParseArgsObjv() TCL_ARGV_GENFUNC plus... artifact: 016fd1302c user: serhiy.storchaka
2024-08-26
22:24
Merge [c28a4551394ad3671]: Fix [7cb7409e05]: Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC. With test... check-in: 5eba108180 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE
2024-04-04
21:09 • Closed ticket [7cb7409e05]: Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC plus... artifact: 62bea068a6 user: jan.nijtmans
21:07
Fix [7cb7409e05]: Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC. With testcase check-in: c28a455139 user: jan.nijtmans tags: trunk, main
20:54
Fix [7cb7409e05]: Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC. With testcase check-in: 7f3767390f user: jan.nijtmans tags: core-8-branch
20:43
Fix [7cb7409e05] by backporting tclIndexObj.c from [c3b23bf0c7] check-in: 8cfa5d1ee9 user: jan.nijtmans tags: core-8-6-branch
20:27
Add testcases for bug [7cb7409e05]: Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC. Mark failing testca... check-in: 81b522c93d user: jan.nijtmans tags: core-8-6-branch
2024-04-03
22:30 • Ticket [7cb7409e05] Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC status still... artifact: beca8dda93 user: emiliano
22:23 • Ticket [7cb7409e05]: 4 changes artifact: d95b639a51 user: jan.nijtmans
22:09
Proposed fix for [7cb7409e05]: Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC check-in: a6a8bc6ffe user: jan.nijtmans tags: bug-7cb7409e05
20:31 • Add attachment parsearg-bug.c to ticket [7cb7409e05] artifact: 8c62836ffa user: emiliano
20:30 • Add attachment parseargs.diff to ticket [7cb7409e05] artifact: 4e451c494d user: emiliano
20:29 • New ticket [7cb7409e05] Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC. artifact: 6abdcc66a1 user: emiliano

Ticket UUID: 7cb7409e05b12cab232b4a86d297ad7bdd9c6336
Title: Tcl_ParseArgsObjv bug with TCL_ARGV_GENFUNC
Type: Bug Created on: 2024-04-03 20:29:51
Submitter: emiliano Assigned to: jan.nijtmans
Subsystem: 13. Index Object Severity: Important
Priority: 5 Medium Last modified: 2024-04-04 21:09:40
Status: Closed Closed by: jan.nijtmans
Resolution: Fixed Closed on: 2024-04-04 21:09:40
Version: 8.7 - trunk
Description:

Tcl_ParseArgsObjv shows a bug in the TCL_ARGV_GENFUNC case, by not properly updating both the objc and srcIndex variables, as read in

https://core.tcl-lang.org/tcl/file?ci=tip&name=generic/tclIndexObj.c&ln=1184-1188

The (integral) return value should be added to srcIndex and substracted from objc.

Attached a simple demo file parsearg-bug.c and a patch to address the issue against core-8-branch.

Compiled with

gcc -shared -o libparse.so -DUSE_TCL_STUBS -I/usr/local/include parsearg-bug.c -L/usr/local/lib -ltclstub8.7

Before the patch:

% load ./libparse.so
% parse
Color: |0|NO COLOR|, Media: |0|NO MEDIA|
% parse -color Nothing
Color: |1|Nothing|, Media: |0|NO MEDIA|
% parse -media A4
unrecognized argument "A4"
% parse -media A4 -color Somecolor
unrecognized argument "A4"
% parse -color othercolor -media Letter
unrecognized argument "Letter"
% parse -color othercolor -media Nosuchmedia
bad media "Nosuchmedia": must be A4, Legal, or Letter

After

% load ./libparse.so
% parse
Color: |0|NO COLOR|, Media: |0|NO MEDIA|
% parse -color Nothing
Color: |1|Nothing|, Media: |0|NO MEDIA|
% parse -media A4
Color: |0|NO COLOR|, Media: |1|Paper size is ISO A4|
% parse -media A4 -color Somecolor
Color: |1|Somecolor|, Media: |1|Paper size is ISO A4|
% parse -color othercolor -media Letter
Color: |1|othercolor|, Media: |1|Paper size is US Letter|
% parse -color othercolor -media Nosuchmedia
bad media "Nosuchmedia": must be A4, Legal, or Letter

There's also a bug in the documentation, which reads (after the Tcl_ArgvGenFuncProc prototype):

"The clientData is the value from the table entry, the interp is where to store any error messages, the keyStr is the name of the argument, objc and objv describe an array of all the remaining arguments, and dstPtr argument to the Tcl_ArgvGenFuncProc is the location to write the parsed value (or values) to."

Here, "...the keyStr is the name of the argument,..." is wrong as there's no such argument in the prototype.

User Comments:
jan.nijtmans added on 2024-04-03 22:23:26:

Thanks! Committed now to a bug-fix branch. I will also add some test-cases.

I wonder if 8.6 has the same bug .....


emiliano added on 2024-04-03 22:30:37:
Indeed, the code on core-8-6-branch looks pretty much the same. It can be easily backported (just 3 lines).

jan.nijtmans added on 2024-04-04 21:09:40:

Fixed in all branches now (core-8-6-branch, core-8-branch and trunk)

Many thanks!


Attachments: