Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[format %llx] overflow

Closed / Fixed2801413fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 17 years ago
Descriptionplain2009-06-04 22:06:02
% set x [expr {1<<(2**29)}]; concat
% set x [expr {$x<<(2**29)}]; concat
% set x [expr {$x<<(2**29)}]; concat
% set x [expr {$x<<(2**29)}]; concat
% incr x -1; concat
% set s [format %#llx $x]; concat
Tcl_SetObjLength: negative length requested: -536870912 (integer overflow?)

Computing the value of numDigits overflows
the int range.
dgpplain2009-06-06 05:04:14
After applying attached patch:

% set max [expr {(1<<(2**31-3)<<(2**31-3)<<(2**31-3)<<(2**31-3))-1}]; concat
% set s [format %#llx $max]; concat
% string length $s
2147483647
% incr max; concat
% set s [format %#llx $max]; concat
max size for a Tcl value (2147483647 bytes) exceeded

This demos ability of [format] to create a numeric
string up to Tcl's limits.

A panic when those limits are exceeded is a bit
jarring, but that's a separate bug/misfeature.
dgpplain2009-06-06 05:04:52
File Added - 329932: 2801413.patch
dgpplain2009-06-11 04:21:37
File Deleted - 329932:
dgpplain2009-06-11 04:22:37
File Added - 330526: 2801413.patch
dgpplain2009-06-11 04:23:23
Updated patch also converts all
[format] panics due to string length
overflow into simple Tcl errors.
dgpplain2009-06-11 04:40:21
allow_comments - 1

patch committed for 8.5.8 and 8.6b2.
Log in (anonymous is fine) to add a comment.

Attachments: