|
2002-04-19
| ||
| 20:09 | • Closed ticket [526717ffff]: list indexing corrupts wide ints plus 7 other ch... artifact: 7c709394b3 user: dkf | |
|
2002-03-14
| ||
| 22:03 | • Ticket [526717ffff]: 4 changes artifact: 60b5f1a787 user: dkf | |
|
2002-03-07
| ||
| 07:36 | • Ticket [526717ffff]: 4 changes artifact: 565a88d666 user: dgp | |
| 00:33 | • New ticket [526717ffff]. artifact: d807739446 user: dgp | |
list indexing corrupts wide ints
Closed / Fixed526717ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2002-03-07 00:33:14
Use of a Tcl_WideInt as a list index will
shimmer it to an "int".
On a 32-bit platform:
% set index [expr {(wide(1)<<31) - 2}]
2147483646
% lindex {1 2 3} $index
% incr index
2147483647
% incr index
-2147483648
Contrast with:
% set index [expr {(wide(1)<<31) - 2}]
2147483646
% incr index
2147483647
% incr index
2147483648
It's worse on 64-bit platforms, where truncation
is to an "int" even though Tcl_Integers are really
longs:
% set index [expr {wide(1)<<32}]
4294967296
% lindex {1 2 3} $index
1
% incr index
4294967297
% lindex {1 2 3} $index
2
So here, we don't lose range on the index values,
but the indexing function "wraps around".
Suspect trouble in TclGetIntForIndex
dgpplain2002-03-07 07:36:26
Logged In: YES user_id=80530 More generally, any place that Tcl_GetIntFromObj is called should be considered suspect.
dkfplain2002-03-14 22:03:44
Logged In: YES user_id=79902 I supoose we could make Tcl_GetIntFromObj know about wideobjs...
dkfplain2002-04-19 20:09:06
Logged In: YES user_id=79902 TclGetIntForIndex really ought to use 'long' and 'long*' not 'int' and 'int*'...
Log in (anonymous is fine) to add a comment.