TCHDB: Fixup 32bit overflows

This is an attempt to fix 32bit overflows in TCHDB in order to squash
ARAKOON-373.

Original patch by Bastiaan Stougie <bstougie@b-virtual.org>.