Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-04-15
22:21 • Closed ticket [92aeb847f9]: proc with more than 2**31 variables plus 7 other... artifact: c99a8eb6c0 user: jan.nijtmans
2025-04-14
08:43
Fix [92aeb847f9]: proc with more than 2**31 variables check-in: 3af3ca8d98 user: jan.nijtmans tags: core-9-0-branch
07:57 • Ticket [92aeb847f9] proc with more than 2**31 variables status still Open wi... artifact: 6772f18789 user: jan.nijtmans
2025-04-10
14:46 • Ticket [92aeb847f9]: 3 changes artifact: 660a520836 user: jan.nijtmans
14:22
First attempt at fixing [92aeb847f9]: proc with more than 2**31 variables. At least, prevent the cra... check-in: 7ccc2a0d76 user: jan.nijtmans tags: bug-92aeb847f9
14:21 • New ticket [92aeb847f9] proc with more than 2**31 variables. artifact: 74d49b98a2 user: jan.nijtmans

proc with more than 2**31 variables

Closed / Fixed92aeb847f9b92cfbd281e9263be3f019ad59192bCreated 2 years agoUpdated 2 years ago
Descriptionwiki2025-04-10 14:21:03
Example (by Ashok):
% proc xx [lrepeat 0x100000000 x] {}
killed

Or explicitly defining the proc in script

% set l [lrepeat 0x100000000 x]; llength $l 4294967296 % writeFile manyargs.tcl [list proc xx $l {return $x}] % exit [apn@tcltk build]$ LD_LIBRARY_PATH=`pwd` ./tclsh manyargs.tcl killed

Note that this has no relation to TIP #626: Those examples don't have more than 2**31 command lines arguments, the "proc" command just has it's second command-line argument being a list with 2**31 arguments. Since Tcl 9.0 already allows large list sizes, Tcl 9.0 should already be able to handle this.

Since a proc with that many variable is unrealistic, setting this ticket as "minor"

Referenced by2
  • 3af3ca8d98Fix [92aeb847f9]: proc with more than 2**31 variables check-in2025-04-14 08:43:50
  • 7ccc2a0d76First attempt at fixing [92aeb847f9]: proc with more than 2**31 variables. At least, prevent the crash. check-in2025-04-10 14:22:57
jan.nijtmanswiki2025-04-10 14:46:19

After 'fix':

$ ./tclsh
% proc xx [lrepeat 0x100000000 x] {}
total mallocs              202168073
total frees                   130242
current packets allocated  202037831
current bytes allocated   43653712110
maximum packets allocated  202037831
maximum bytes allocated   43653712110
procedure "xx": arg list contains too many (4294967296) entries
%
%
% exit

jan.nijtmanswiki2025-04-14 07:57:45

After better fix:

$ ./tclsh
% proc xx [lrepeat 0x100000000 x] {}
total mallocs              163959265
total frees                   130503
current packets allocated  163828762
current bytes allocated   41896099036
maximum packets allocated  163828762
maximum bytes allocated   41896099036
procedure "xx": memory error
%

Actually, it depends where the allocation error occurs. It might happen in a Tcl_Alloc(), it also might happen in Tcl_CreateHashEntry().

In the first case, we might use Tcl_AttemptAlloc() and do a proper cleanup. In the other case, we would need a Tcl_AttemptCreateHashEntry() (TIP!)

jan.nijtmanswiki2025-04-15 22:21:55

Fixed [here]

Log in (anonymous is fine) to add a comment.