| Ticket UUID: | 3067036 | ||
| Title: | Appending to 0-length byte array causes busy loop. | ||
| Type: | Bug | Created on: | 2010-09-15 17:52:43 |
| Submitter: | sbron | Assigned to: | dkf |
| Subsystem: | 12. ByteArray Object | Severity: | |
| Priority: | 5 Medium | Last modified: | 2010-09-16 05:14:11 |
| Status: | Closed | Closed by: | dkf |
| Resolution: | Fixed | Closed on: | 2010-09-15 22:14:11 |
| Version: | obsolete: 8.6b1.1 | ||
| Description: | ||||
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. | ||||
| User Comments: | ||||
sbron added on 2010-09-16 00:52:44:
File Added - 386772: tclBinary.c.patch andreas_kupries added on 2010-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. dgp added on 2010-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. dkf added on 2010-09-16 05:14:11:
allow_comments - 1 Fixed in HEAD by jumping straight to enough space in the zero-allocated-before case. | ||||
Attachments:
- tclBinary.c.patch [download] added by sbron on 2010-09-16 00:52:43. [details]
