Fix some cast_int calls.

We can't call cast_int<unsigned> on something intentionally
larger than max(unsigned).