Tcl Source Code

View Ticket
Login
Ticket UUID: 1284178
Title: [format %h?] rejects valid integers
Type: Bug Version: obsolete: 8.4.11
Submitter: dgp Created on: 2005-09-07 18:17:48
Subsystem: 16. Commands A-H Assigned To: dkf
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2005-10-14 04:46:33
Resolution: Fixed Closed By: dkf
    Closed on: 2005-10-13 21:46:33
Description:
% 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.
User Comments: dkf added on 2005-10-14 04:46:33:
Logged In: YES 
user_id=79902

Fixed in 8.4 branch.

dgp added on 2005-10-14 03:40:35:
Logged In: YES 
user_id=80530


my position is that the tests
themselves are broken.

dkf added on 2005-10-14 03:27:51:
Logged In: YES 
user_id=79902

Fixing this breaks format-17.1 and format-18.2

dgp added on 2005-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

dgp added on 2005-09-12 08:54:31:

File Deleted - 148370: 



File Added - 148760: 1284178.patch

dgp added on 2005-09-12 08:54:29:
Logged In: YES 
user_id=80530

corrected patch now attached

dgp added on 2005-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

dgp added on 2005-09-08 01:34:05:

File Added - 148370: 1284178.patch

dgp added on 2005-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.

dgp added on 2005-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?

Attachments: