+1 on the ensure total capacity to account for the fact that we add a null byte before returning. thanks matklad