Oops, work out expanded buffer length before allocating it...