TclStackAlloc argument type
Closed / Works For Me32337edbd60e90c1d6aaa9c9b0a681c2abb4950cCreated 8 years agoUpdated 8 years ago
Descriptionplain2019-02-01 16:31:29
On the core-8-branch, the internal routine TclStackAlloc() takes a second argument of type int to specify the number of bytes to allocate. Recently (for example, https://core.tcl-lang.org/tcl/info/a6cbc60ca29e236b ) callers of TclStackAlloc have had the expressions of their second argument values modified. It's not clear to me that the new expressions or the old expressions take care to avoid integer overflow.
dgp Ticket [32337edbd6]: 3 changes
[History diff]2019-02-01 16:31:41
jan.nijtmansplain2019-02-02 18:10:45
The only modification I see in the TclStackAlloc() call is removal of the (unsigned) cast. This type cast is useless: since TclStackAlloc() has an int argument, overflow is always possible, it was and still is. Since TclStackAlloc() is meant to allocate a small number of 'things', and general the call does something like TclStackAlloc(numThings * sizeof(thing)), I don't think much can be done without changing the argument of TclStackAlloc() to something bigger as int. That's already done in Tcl 9.0. So, I would suggest to leave it as-is for the Tcl-8 line, it's not worth the trouble. as long as numThings is small compared to the total memory, it will continue to work fine. For Tcl-9 it's fixed already, since TclStackAlloc() got a size_t argument. For 32-bit platforms it can handle double the sizes as it could in Tcl-8. For 64-bit platforms, there's practically no limit any more.
Log in (anonymous is fine) to add a comment.