Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2005-10-14
04:46 • Closed ticket [1284178fff]: format %h? rejects valid integers plus 7 other... artifact: 99e9f6870e user: dkf
03:40 • Ticket [1284178fff]: 4 changes artifact: 117b9c9051 user: dgp
03:27 • Ticket [1284178fff]: 4 changes artifact: 1c2713f94c user: dkf
00:52 • Ticket [1284178fff]: 4 changes artifact: 0f53f39870 user: dgp
2005-09-12
08:54 • Ticket [1284178fff]: 4 changes artifact: be350dc3f4 user: dgp
08:54 • Add attachment 1284178.patch to ticket [1284178fff] artifact: 84417842d5 user: dgp
08:54 • Ticket [1284178fff] format %h? rejects valid integers status still Open wi... artifact: 4d1e21bf77 user: dgp
2005-09-11
08:58 • Ticket [1284178fff]: 4 changes artifact: 38d26c81d6 user: dgp
2005-09-08
01:34 • Ticket [1284178fff]: 4 changes artifact: 79123a72ff user: dgp
01:34 • Ticket [1284178fff]: 4 changes artifact: 8f16c9d909 user: dgp
01:29 • Ticket [1284178fff]: 4 changes artifact: ae2493a948 user: dgp
2005-09-07
18:17 • New ticket [1284178fff]. artifact: 3fc5838fb3 user: dgp

[format %h?] rejects valid integers

Closed / Fixed1284178fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-09-07 18:17:48
% format %hu 0xffff
65535
% format %hu 0x10000
0
% format %hu 0xffffffff
65535
% format %hu 0x100000000
integer value too large to represent

It's clear that %hu truncates to 
short int size before formatting, but
fails to do the same truncation when
given a wide integer value.  It just
rejects those, without a good reason.
dgpplain2005-09-08 01:29:50
Logged In: YES 
user_id=80530


A related issue is integer [format]s without
a length specifier, for example:

% format %u 0xffffffff
4294967295
% format %u 0x100000000
integer value too large to represent

As with the "h"-constrained formatting,
we could truncate to the native length
of a long before formatting and accept
the wide argument.  Doing that would
produce:

% format %hu 0x100000000
0

However, this behavior is actually
tested by the test suite via tests
format-17.1 and format-18.2 .  The
restriction and these test don't really
make sense to me, but perhaps a
maintainer knows better?
dgpplain2005-09-08 01:34:03
Logged In: YES 
user_id=80530


Here's a patch that makes
all of [format]'s integer
conversion specifiers accept
all of Tcl's valid integer values.
dgpplain2005-09-08 01:34:05
File Added - 148370: 1284178.patch
dgpplain2005-09-11 08:58:21
Logged In: YES 
user_id=80530


Do not accept that patch.

It introduces a new bug:

% format %ld [expr wide(3000000000)]
-1294967296
dgpplain2005-09-12 08:54:29
Logged In: YES 
user_id=80530

corrected patch now attached
dgpplain2005-09-12 08:54:31
File Deleted - 148370: 



File Added - 148760: 1284178.patch
dgpplain2005-10-14 00:52:02
Logged In: YES 
user_id=80530


fixed on HEAD by TIP 237 merge.

Still needs attached patch applied
to fix in 8.4.11
dkfplain2005-10-14 03:27:51
Logged In: YES 
user_id=79902

Fixing this breaks format-17.1 and format-18.2
dgpplain2005-10-14 03:40:35
Logged In: YES 
user_id=80530


my position is that the tests
themselves are broken.
dkfplain2005-10-14 04:46:33
Logged In: YES 
user_id=79902

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

Attachments: