Here's an updated pair which fixes a bug where realloc was reading off the source, and then addresses a TODO item to shrink the buffer when the new size is much smaller.