Sorry about the duplicate bug report; I merged it into this one. Here's the patch again. (Merged report seemed invisible in the web interface.)