Fix ring buffer size and overrun detection