Rewrite timeout computation in a way that is less prone to overflow.