Artifacts Associated With Ticket 2848176fffffffffffffffffffffffffffffffff
Ticket change [e6127f382e] (rid 104237) by kchansen on 2009-09-01 03:31:19:
- assignee initialized to: "dgp"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Both crc16.tcl and crc32.tcl use a variable named "signmask", that is constructed from another variable named "signbit". For 32-bit data, signbit is 0x8000000. For 32-bit CRCs, the signmask appears to be designed to mask off the high-byte, i.e. it should end up 0x00ffffff. Signmask is computed as follows: set signmask [expr {~$signbit>>7}] Printing $signbit shows the expected value of 0x80000000: % puts $signbit 0x80000000 But if we print the bit-complement of this (which in 32-bit land we expect to be positive) we get: % expr ~$signbit -2147483649 When we format this using "format 0x%x" we oddly get: % format 0x%x [expr ~$signbit] 0x7fffffff Even worse, the above calculations for signmask now no longer give 0x00FFFFFF, but rather 0xFEFFFFFF, which is pretty much guaranteed to give the wrong result. It looks like the number is kind of living in both "long-land" and 32-bit-land. In long-land the 0x80000000 gets sign-extended from 32-bit-land, and after that the bit-complement would indeed be still negative. But the format statement seems to think the number is 32-bit-land-only.... Help! - foundin initialized to: "obsolete: 8.5.7"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "kchansen"
- subsystem initialized to: "48. Number Handling"
- title initialized to:
Invalid results from "expr", v8.4.*, v8.5.*, v8.6.*
- type initialized to: "Bug"
Ticket change [176b74878c] (rid 122488) by kchansen on 2009-09-01 10:33:39:
- icomment:
Because this deals with math and breaks some existing code (crc-32 calculations) I am hoping my assigning the highest priority will stick....
- login: "kchansen"
- mimetype: "text/plain"
- username: "kchansen"
- icomment:
Ticket change [5001bd68d4] (rid 125907) by kchansen on 2009-09-01 10:33:40:
- priority changed to: "9 Immediate"
Ticket change [ad9bbfe57b] (rid 101498) by dkf on 2009-09-01 15:27:44:
- icomment:
It'd help a lot if you could let us know which crc*.tcl scripts have this problem. (The issue is probably that the code therein is not 64-bit safe, and so would have actually been a problem on some platforms even before 8.4. Though those platforms were much less common back then.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [1f5999fc2d] (rid 91133) by kchansen on 2009-09-01 21:31:37:
- icomment:
...first line of the description: "...crc16.tcl and crc32.tcl...." These are both in the crc portion of "tcllib".
- login: "kchansen"
- mimetype: "text/plain"
- username: "kchansen"
- icomment:
Ticket change [7cea7f851d] (rid 97162) by dgp on 2009-09-02 00:14:23:
- icomment:
This is not a bug. It is an intentional feature change. Starting with release Tcl 8.4.0 in 2002 (!) the numeric literal value "0x80000000" is taken as the number 2147483648 . This is an incompatible change from Tcl 8.3 and earlier where the interpretation was platform dependent. On 32-bit systems it was the number -2147483648 and on 64-bit systems it was the number 2147483648. It was TIP 72 that started this change, and since then TIP 237 extended the change so that integer literals are interpreted within a system of unlimited range and no overflows at all. If you want a negative number in hex notation, you must lead with the minus sign. Also, do not over look the "l" and "ll" modifers in your [format] spec's: % format %#x [expr ~0x80000000] 0x7fffffff % format %#lx [expr ~0x80000000] 0xffffffff7fffffff % format %#llx [expr ~0x80000000] -0x80000001 Sounds like the crc*.tcl files you have are buggy. Even when they might have been used with Tcl 8.3, they were still buggy, since they did not work on 64-bit systems. Check that you are still using some that are out of date. If not, report the bugs to the maintainer(s) of the package(s). The possibly legitimate gripe against Tcl is that Tcl does not provide any good tools in the built-in command set to easily, efficiently, and with complete cross-platform agreement operate on data known to be "32-bit integers" or "64-bit integers". Tcl leaves too many of the definitional details to the underlying C implementation. Tcl scripts that really want to operate on 32-bit buffers find that they are forced to to a lot of masking against 0xFFFFFFFF to get the job done right. Whether the right answer to this problem is more operators and options in Tcl's built-ins or a good extension or two, is a matter for someone motivated to pursue.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [71b4ff28ad] (rid 100734) by dgp on 2009-09-02 00:14:25:
- closedate changed to: "2009-09-01T17:14:25"
- closer changed to: "dgp"
- icomment:
allow_comments - 1
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
- username: "dgp"