vec: with_capacity: check for overflow

Fixes #10271