Fixed size_t Warnings

Fixed size_t to int conversion warnings by checking first that size_t
can hold at most an int and then casting the value to an int.