Fix potential divide-by-zero exception.