Try to fix Coverity errors with RE2 interface

Adds some basic parameter validation to RE2 interface routines taking in 
nsubmatch/ncaptures since these must be ints for RE2 but are int64
in the interface.

Adds an overflow check to MAYBE_STACK_ALLOC so that we don't allocate
if count * sizeof(type) would overflow. This should hopefully correct
a Coverity error.