Fix an arithmetic overflow which can cause segv.
Merge.