Fixes owerflow warning during compilation.
Merge pull request #3014 from bfg1981/master

Avoid overflow warning during compilation.

Note the warning is invalid. But it doesn't hurt to range check the input variable before it is compared to the lengths of the internal buffers.