fix undefined behaviour in rule extract (thanks Barry)