Fix unsigned int overflow reported by UBSan (#759)