Prevent various possible buffer overruns, and one missed PROTECT added. (PR#15990}


git-svn-id: https://svn.r-project.org/R/trunk@66671 00db46b3-68df-0310-9c12-caf00c1e9a41