Avoid signed/unsigned comparsion in magic()