Fix some of the problems that bde pointed out to me some time ago.
- buffer expansions were not working right due to a return code botch.
- signed types instead of size_t's meant somebody else went and put casts in, I've changed the types to what they should have been.