This Space for Rent

Second patch of the week!

Adding extended attributes and percentage widths & heights to image links exposed a delightful Discount bug that’s been there since I put amalloc in 17 years ago.

The problem was that the amalloc() function (#defined to just malloc() in amalloc.h) was using the libc calloc() to grab memory, and calloc() helpfully by design initializes the memory to nulls, which just happens to be what I need to null terminate strings by default.

This was “great” for me, and I probably had a reason for doing it, but there exist malloc implementations (which are exposed if you built discount w/o amalloc) that don’t initialize the memory unless you ask for it, and which often aggressively initialize that memory to something other than null.

So I changed amalloc to initialize the new buffer to 0x8fs and boy did the discount test suite have things to say about this!

It’s allegedly fixed now (I try to explicitly null-terminate Cstrings and to explicitly use calloc() when I need a buffer for structures) and it out there as Discount 3.0.1.2.

I’m sure I’ll find some other places where I was making assumptions about amalloc, but the obvious ci-killing places seem to be gone for now.