Appending to 0-length byte array causes busy loop.
Closed / Fixed3067036fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-09-15 17:52:43
The code below goes into a busy loop with 100% cpu usage: set f [open /dev/null] chan configure $f -blocking 0 -translation binary set str [read $f 2] append str [binary format a* foo] The problem is in TclAppendBytesToByteArray(). This function tries to calculate the needed memory by doubling the currently allocated space until it is big enough. That method fails miserably when starting with an allocated space of size 0, as is the case in the code above.
sbronplain2010-09-16 00:52:44
File Added - 386772: tclBinary.c.patch
andreas_kupriesplain2010-09-16 00:58:11
Interesting. I remember seeing a different place where memory doubling was done which did things a bit differently: It doubled the length of the "requested" space, not the current one. As 'requested > allocated' this could never be 0. ... Remembering more, that was somewhere in appending to a list. I guess the "appending to string/bytearray" should be rewritten to the same scheme.
dgpplain2010-09-16 01:14:20
FWIW, I think it would be good to cover as many of these growth algorithms as possible with just one (set of) macro templates.
dkfplain2010-09-16 05:14:11
allow_comments - 1 Fixed in HEAD by jumping straight to enough space in the zero-allocated-before case.
Log in (anonymous is fine) to add a comment.
Attachments:
- tclBinary.c.patch [download] added by sbron on 2010-09-16 00:52:43. [details]