Make sure buffer has room for terminating null

Thanks to Josh Bressers for this suggestion