ring: fix overflow in memory size calculation