[Haskell-cafe] Fixed: Crash!

Andrew Coppin andrewcoppin at btinternet.com
Fri Oct 24 14:20:56 EDT 2008

Andrew Coppin wrote:
> I'm actually wondering if my code is writing off the end of an array 
> and this "just happens" to hit some data structure used by GTK+? (In 
> which case, minute changes in linkage, etc., would disturb the bug.)

Yep, that's what it was. (Although not where I was expecting it to be, 
which kept me guessing for a while...) I thought that all write 
operations go to the IOUArray, except for the loop that copies it to the 
Pixbuf. (This loop is constructed such that it cannot go out of bounds, 
while the ad-hoc writing uses user-supplied coordinates.) I forgot about 
the second drawing pass, which does write directly to the Pixbuf. *This* 
appears to be the source of my bug; if you add a range check, the bug 
goes away. (Oddly, I added the range check back to the IOUArray as well, 
and even though it's writing the same coordinates, no error is reported. 
I guess I must have an off-by-one bug as well...!)

So there you have it. Premature optimisation => buffer overrun => end of 
civilisation as we know it. :-/

More information about the Haskell-Cafe mailing list