Port to Linux. Fix integer overflows.